Reputation: 394
I have found on this answer the regex to find a string between two characters. In my case I want to find every pattern between ‘
and ’
. Here's the regex :
(?<=‘)(.*?)(?=’)
Indeed, it works when I try it on https://regex101.com/.
The thing is I want to use it with grep
but it doesn't work :
grep -E '(?<=‘)(.*?)(?=’)' file
Is there anything missing ?
Upvotes: 0
Views: 1393
Reputation: 8769
Those are positive look-ahead and look behind assertions. You need to enable it using PCRE(Perl Compatible Regex) and perhaps its better to get only matching part using -o
option in GNU grep
:
grep -oP '(?<=‘)(.*?)(?=’)' file
Upvotes: 2