I am learning regex. One of the problem requires me to find all words that begin with a vowel. I am using Python's re
module for evaluating the regular expression.
Here is the regex I made:
\<[aeiouAEIOU].*?\>
The above regex does not work with the \<
and the \>
anchor but works with the \b
anchor. Why?
"Does not work" is not correct; one works in some regex dialects, the other in others.
Most "modern" regex dialects (Python, Perl, Ruby, etc) use \b
as the word boundary, on both sides.
More traditional regex dialects, like the original egrep
, use \<
as the left word boundary operator, and \>
on the right.
(Strictly speaking, Al Aho's original egrep
did not have word boundaries; this feature was added later. Maybe see https://stackoverflow.com/a/39367415/874188 for a one-minute summary of regex history.)