PCRE to RE2

756 views
Skip to first unread message

Adam Takahashi

unread,
Jul 25, 2019, 1:11:15 AM7/25/19
to golang-nuts
Hello,

I currently have a regex in PCRE that is
  • (.|\r|\n)*?(?=FOO)
It reads in a random number of multiple lines of sentences, and stops when it sees the word FOO in all caps. I am have problems converting this to a valid RE2 expression. 
Any advice would help. Thanks.

andrey mirtchovski

unread,
Jul 25, 2019, 1:25:51 AM7/25/19
to Adam Takahashi, golang-nuts
I'm sorry to say that this list isn't RE2-specific (although one of
the main Go contributors wrote RE2). you will probably get very good
suggestions on how to convert that to Go's regex, which are RE2-like
and I hope you find your answer.

A good additional step to do for this particular list is to concoct a
small go example on play.golang.org with some sample input that you're
struggling with.
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/2b88000d-7344-40b6-8830-41f1f762962e%40googlegroups.com.

Ian Lance Taylor

unread,
Jul 25, 2019, 1:28:49 AM7/25/19
to Adam Takahashi, golang-nuts
The Go regexp library does not support (?=xxx).

It would be trivial to write this regexp as a loop that reads a series
of lines and stops when it finds a line containing FOO. See
https://commandcenter.blogspot.com/2011/08/regular-expressions-in-lexing-and.html
.

Ian
Reply all
Reply to author
Forward
0 new messages