I am using grep for extracting string from file.
If my regular expression looks like:
I will get an error "Lookbehind assertion is not fixed length". Problem is in \s*. (?<=) works only if match if fixed size.
Regular expression
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:
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
(?<=^ManagementCidr\s*=\s*).*
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(.*)
4 comments:
Thank you!
You saved me a lot of trouble and time :)
Thanks for posting this!
Thanks man!
Never heard of \K before.
Thank you for this!
Post a Comment