Kudithipudi.Org

July 30, 2012

HOW TO : Use word boundaries in Regular Expressions

Filed under: HOWTO,Technology — Vinay @ 4:04 pm

If you are every looking to match strings as a whole word instead of literal strings using a regular express, Word Boundaries are your friend

For example if you are looking to match a string of 10 numbers in a log file, you can use

grep -i '\b[0-9]\{10,\}\b' --color -H -n FILE_NAME_TO_SEARCH 

The \b is the option that tells grep to look for a word character.

More information about the option is available at http://www.regular-expressions.info/wordboundaries.html

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress