Travis Crum
Travis Crum

Reputation: 399

regex negative lookbehind is doing a normal lookbehind or gives an error

I'm trying to get regex to capture some data with a negative lookbehind so it won't match if a certain string preceeds it. I know there are two basic formats but neither are working. I'm doing this in a search app and can't use java to augment so the solution has to be purely with regex.

This format gives me an error saying "Regular Expression syntax-error: invalid quantifier"

(?<!Product) Type : (.*?)<

This format acts a normal lookbehind and captures only when Type is preceded by Product:

(?!=Product) Type : (.*?)<

What am I doing wrong?

Upvotes: 6

Views: 421

Answers (1)

danseery
danseery

Reputation: 486

(?<!Product)[ ]Type[ ]:[ ](.*?)<

This should do what you want. You have to wrap the spaces in brackets []

It will not match:

Product Type : xyz<

but it will match and capture xyz:

Other Type : xyz<

Upvotes: 3

Related Questions