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.



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 '<!--.*-->' ./





is another alternative.

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




All Articles