Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match HTML Comments With Grep and Regex

Tags:

regex

grep

I have a series of files containing html comments (<!-- some comment -->) that I'm trying to match using grep

Comments span across only 1 line.

Here is my command

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

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

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

It works.

The original regex works in javascript, but grep doesn't seem to like it for some reason unknown to me.

Thanks.

like image 637
Trevor Avatar asked Nov 22 '25 12:11

Trevor


1 Answers

The default regex engine (POSIX basic) in grep does not support ?. This works, since . will also match the space:

grep -rl '<!--.*-->' ./
like image 123
Greg Inozemtsev Avatar answered Nov 24 '25 04:11

Greg Inozemtsev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!