Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Regular Expression - Operator Priority


May 28, 2021 Regular expression


Table of contents


Regular Expression - Operator Priority

Regular expressions are evaluated from left to right and follow priority order, much like arithmetic expressions.

Operations are performed from left to right at the same priority, and operations at different priorities are first high and then low. The following table illustrates the order of precedence of the various regular expression operators from highest to lowest:

运算符 描述
\ 转义符
(), (?:), (?=), [] 圆括号和方括号
*, +, ?, {n}, {n,}, {n,m} 限定符
^, $, \任何元字符、任何字符 定位点和序列(即:位置和顺序)
| 替换,"或"操作
字符具有高于替换运算符的优先级,使得"m|food"匹配"m"或"food"。若要匹配"mood"或"food",请使用括号创建子表达式,从而产生"(m|f)ood"。