4

Simply put:

echo "xxxxx Tyyy zzzzz" | egrep "\byyy\b" 

(no match which is correct)

echo "xxxxx T-yyy zzzzz" | egrep "\byyy\b" 
xxxxx T-yyy zzzzz

I dont want it to match like it does in the second expression, please advise how I can achieve this, thanks.

Jahed Uddin
  • 181
  • 10

1 Answers1

3

You can use:

echo "xxxxx T-yyy zzzzz" | egrep "(^|[^-])\byyy\b([^-]|$)"

Where (^|[^-])\byyy\b([^-]|$) will match start or non-hyphen on LHS and end or non-hyphen on RHS of the matched word yyy.

anubhava
  • 713,503
  • 59
  • 514
  • 593