Regular Expression — Using of \b and \B together. Part 3
Using \B and \b together: Finding pattern at the NOT at RIGHT edge of words.
Continues from Previous Post: Regular Expression — Use of \B (Not Word Edges) Part 2
For ‘\B’ at the beginning of the pattern and ‘\b’ at the end of the pattern
$grep ‘\Bcat\b’ wordedge.txt
Be unique do not be a copycat.
when ‘\B’ is at the beginning of the pattern and ‘\b’ at the end of the pattern, ‘\B’ makes sure that the pattern is not at the beginning of the word and ‘\b’ on the end make sure the word is on the right edge of the word.
So in this case you will find the patterns always at the right edge of the word.
This is different than using just ‘\b’ at the end of the pattern because just using ‘\b’ allows us to select the whole word itself if it is the pattern.
Now vice-versa:
For ‘\b’ at the beginning of the pattern and ‘\B’ at the end of the pattern.
$grep ‘\bcat\B’ wordedge.txt
old weapon used to hit birds is catapult.
when ‘\b’ is at the beginning of the pattern and ‘\B’ at the end of the pattern, ‘\b’ makes sure that the pattern is at the beginning of the word and ‘\B’ on the end make sure the word is NOT on the right edge of the word.
So in this case you will find the patterns always at the left edge of the word.
This is different than using just ‘\b’ at the beginning of the pattern because just using ‘\b’ allows us to select the whole word itself if it is the pattern.
Hope this was useful.
[enough]





