Friday, August 03, 2012

Lookbehind assertion is not fixed length

I am using grep for extracting string from file.
If my regular expression looks like:

grep -P -o -z '(?<=^ManagementCidr\s*=\s*).*'

I will get an error "Lookbehind assertion is not fixed length". Problem is in \s*. (?<=) works only if match if fixed size.

Regular expression

is OK in C# (you can test it using this great tool).

Fortunately, after hours of googling I found that if you put in regular expressing for grep \K it will reset matched text at this point. So grep command that do what I want will be:

grep -P -o -z '^ManagementCidr\s*=\s*\K(.*)

No comments: