Matt
Matt

Reputation: 531

Negative lookbehind in go with endline match?

I'm trying to match all lines that start with < and subsequent text but I don't want to catch <3. The regex that matches this in JS is ^<(?!3$).*$

<3       // doesn't match
<34      // matches
<bla bla // matches

Thanks for your help

Upvotes: 0

Views: 53

Answers (1)

VonC
VonC

Reputation: 1327524

If you really had to support a complex regex without having to do multiple pass, you can use Go projects like skybet/goback which does provide extended regex features (extended compared to the re2 syntax)

re := regexp.MustCompile(`(?<=a[0-9]{3,5})a`)
fmt.Println(re.MatchString("a12a"))     // false
fmt.Println(re.MatchString("a12345a"))  // true

But, as mentioned in this library:

The implementation does NOT guarantee linear processing time.

Upvotes: 1

Related Questions