-1

I just saw a post where the regex to search for email addresses in a text file is given by:

grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" file.txt

I wanted to know the meaning of the \b at the start and the end.

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
Murphy
  • 536
  • 6
  • 13

1 Answers1

0

Quoting from here:

The metacharacter \b is an anchor like the caret and the dollar sign. It matches at a position that is called a "word boundary". This match is zero-length. ...

Simply put: \b allows you to perform a "whole words only" search using a regular expression in the form of \bword\b. A "word character" is a character that can be used to form words. All characters that are not "word characters" are "non-word characters".

GhostCat
  • 137,827
  • 25
  • 176
  • 248