I discovered that I can use =~ operator instead of expr command in my 4.2.10(1) BASH. It is much faster (within a command) than expr and this fact could be important inside in a loop with large repetition.
I was able to use most of the meta characters of regular expression but not all.
For example I can check a string matches exactly 3 repetitions of (one small letter, one digit, one dot):
[[ "b3.f5.h3." =~ ^([a-z][0-9]\.){3}$ ]] && echo OK
OK
and I can select matched substrings:
[[ "whatis12345thetwo765nmbers" =~ ^[a-z]+([0-9]+)[a-z]+([0-9]+) ]] && \
echo "The two number fields are: ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}"
The two number fields are: 12345 765
But I would like to use more meta characters, such as the ones listed on this TLDP page.
I would especially like to match word boundaries: \b, \B, \<, \> .
I tried to find an answer in the Advanced Bash-Scripting Guide (in Chapters 18 and 37) but was unsuccessful.
Where can I find a detailed description of =~ operator?
At the moment I am interested only in BASH and not in gawk, sed, perl or other tools.
(^|[[:space:]])WordToMatch($|[[:space:]])or similar. It's not exactly identical semantics, but frequently good enough.