Matching HTML comments with Grep and Regex

I have a series of files containing html comments ( <!-- some comment -->

) which I am trying to match usinggrep

Comments only cover one line.

Here is my command

grep -rl '<!--.*?-->' ./

      

It doesn't match. However, if I run grep with this regex:

grep -rl '<!--.*?' ./

      

He works.

The original regex works in javascript, but grep doesn't seem to like it for a reason I don't know.

Thank.

+3


source to share


2 answers


The default regex mechanism (POSIX basic) in grep does not support ?

. This works as .

it will match a space as well:



grep -rl '<!--.*-->' ./

      

+1


source


Egrep

is another alternative.



egrep -r '<!--.*?-->' ./

      

0


source







All Articles