Why there are so many regular expression variants? [closed]
For historical reasons. There's no one definition of "Regular expression" syntax. The concept of a regular expression itself has nothing to do with the actual syntax that formally describes it. People have come up with different ways of saying the same thing, hence different styles of regex syntax.
However, you'll find that there are mostly two groups of definitions around these days:
POSIX regular expressions that specify Basic (BRE) and Extended Regular Expressions (ERE). The confusion begins where for example, Basic Regular Expressions use
\( \)
to denote a group, and Extended Regular Expressions use( )
for that.Perl-based regular expressions. Perl regular expressions define a more consistent syntax, where for example a backslash will always escape a non-alphanumeric character. Perl regex syntax is found in many popular programming languages these days, from Java to Ruby.
You can check out the Wikipedia article on regex syntax for more info.