Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

search with grep for words beginning and ending with

Tags:

regex

grep

How to grep something which begins and end with a character

ABC-0
ABC-1
ABC-10
ABC-20

I wanto to grep -v for ABC-0 and ABC-1

like image 289
kal Avatar asked Oct 02 '09 06:10

kal


1 Answers

If you are trying to match words use \b as the word delimiter, like this:

\b[A-Za-z]-\d+\b

from this reference:

\b - Matches at the position between a word character (anything matched by \w) and a non-word character (anything matched by [^\w] or \W) as well as at the start and/or end of the string if the first and/or last characters in the string are word characters.

like image 79
João Portela Avatar answered Oct 12 '22 12:10

João Portela