WHAT is wrong with the following regular expression and HOW does one fix it?:
\b\*\b
The above pattern should be interpreted as word boundary followed by star followed by word boundary.
star, Jeffrey E. F. Friedl's preferred term for the asterisk metacharacter must be escaped by preceding it with a \
backslash when one does not wish to use it as a metacharacter.
For the string *
"spacestarspace", the above regular expression fails.
Regex Tester for .NET tests the above regular expression.
Here is the same example as above, but with the ignore case option selected.
The following tweak attempts also fail:
\b[\*]\b
character class for star
\b(\*)\b
constraining parentheses
other combinations that were tried also failed.
Searching with Google, including SO and MSDN, has been unsuccessful.
in a
, \ba\b
the a
is found;
in *
, \b\*\b
fails to match the star
The same results occur in LINQPad 5 and Visual Studio 2015.
Edit (this fixes the problem for c# .NET) TIMTWOTDI:
\B\*\B
See this in the Regex Tester for .NET.
Wiktor Stribiżew's comment was the clue that helped.
On page 133 of the third English edition of Friedl's book, the author wrote "it would make sense if the word boundaries agree with \w, but that is not always the case".