Regex behaviour with angle brackets
grep, regex
Solution
AS @hwnd said `\<` matches the begining of the word. `ie` a word boundary `\b` must exists before the starting word character(character after `\<` in the input must be a word character),
In your example,
echo "<firstname.lastname@domain.com>" | egrep "<lastname@domain.com>"
In the above example, egrep checks for a literal `<` character present before the lastname string. But there isn't, so it prints nothing.
$ echo "<firstname.lastname@domain.com>" | egrep "\<lastname@domain.com>"
<firstname.**lastname@domain.com>**
But in this example, a word boundary `\b` exists before `lastname` string so it prints the matched characters.
Some more examples:
$ echo "namelastname@domain.com" | egrep "\<e@domain.com"
$ echo "namelastname@domain.com" | egrep "\<lastname@domain.com"
$ echo "namelastname@domain.com" | egrep "\<com"
namelastname@domain.**com**
$ echo "<firstname.lastname@domain.com>" | egrep "\<@domain.com>"
$ echo "n-ame-lastname@domain.com" | egrep "\<ame-lastname@domain.com"
n-**ame-lastname@domain.com**
Problem
Please explain to me why the following expression doesn't output anything: ``` echo "<firstname.lastname@domain.com>" | egrep "<lastname@domain.com>" ``` but the following does: ``` echo "<firstname.lastname@domain.com>" | egrep "\<lastname@domain.com>" ``` The behaviour of the first is as expected but the second should not output. Is the "\<" being ignored within the regex or causing some other special behaviour?