Regular expression pipe confusion

The first pattern without the parenthesis is equivalent to /(^a)|(b$)/.
The reason is, that the pipe operator (“alternation operator”) has the lowest precedence of all regex operators: http://www.regular-expressions.info/alternation.html (Third paragraph below the first heading)

Leave a Comment