Using Grep with Regular Expressions: Examples
Many of you may be wondering how to use the regular expression syntax with the infamous ‘grep’ tool.
It took me awhile to figure this out, so I’m posting it so I will always remember it’s on my blog!
First, you have to use -E to invoke extended regular expressions with grep, and you’ll also have to […]
Many of you may be wondering how to use the regular expression syntax with the infamous ‘grep’ tool.
It took me awhile to figure this out, so I’m posting it so I will always remember it’s on my blog!
First, you have to use -E to invoke extended regular expressions with grep, and you’ll also have to add the parameters: -zl otherwise it won’t treat the string as one line (which it has to do to nested matching).
For example I want to find all tags named “<Bar>” nested inside “<Foo>”:
<Foo>
<Bar>
$grep -rzlE ‘<Foo[^>]*>[^>]*<Bar>’ .



















