I wanted to test this (<\/?)+[a-z]+(>)
regex against different tools to see what I would get. Actually the purpose of the experiment was to test how each of the utility displayed results back to console. Basically it searches the below html document and then matches all html tags. To my surprise the result that I got from grep, ack and ag varied significantly. grep did not even return anything back
Ack
Grep
Ag
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
body and so
df
s;kl,
<p>Hello code kit</p>
<p>Thats pretty great</p>
<p>Really neat!</p>
<p>I wanna be a developer for life</p>
<nav>
breeee!
</nav>
I am in love
<p>Ummmmmm!</p>
wtf
okay buddy!
<p>
I took that shit out
</p>
<aside>
eeem
</aside>
Sometimes u really get bored
</body>
</html>
Just for sanity, I went ahead and tested it on rubular and viola! the output was just like when I used ag from the CLI. So my question is why does the result of this simple regex varies based on the tool used
You need to use an extended regular expression for grep
to work in this case. Add the -E
flag. I get pretty much the same output for all three tools in that case: