0

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 ?

Community
  • 1
  • 1
Laurent Mesguen
  • 354
  • 2
  • 6
  • 22

1 Answers1

2

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
riteshtch
  • 8,629
  • 4
  • 25
  • 38