Please explain to me why the following expression doesn't output anything:
echo "<[email protected]>" | egrep "<[email protected]>"
but the following does:
echo "<[email protected]>" | egrep "\<[email protected]>"
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?
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 "<[email protected]>" | egrep "<[email protected]>"
In the above example, egrep checks for a literal <
character present before the lastname string. But there isn't, so it prints nothing.
$ echo "<[email protected]>" | egrep "\<[email protected]>"
<firstname.**[email protected]>**
But in this example, a word boundary \b
exists before lastname
string so it prints the matched characters.
Some more examples:
$ echo "[email protected]" | egrep "\<[email protected]"
$ echo "[email protected]" | egrep "\<[email protected]"
$ echo "[email protected]" | egrep "\<com"
namelastname@domain.**com**
$ echo "<[email protected]>" | egrep "\<@domain.com>"
$ echo "[email protected]" | egrep "\<[email protected]"
n-**[email protected]**
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With