?:代表一个字符
*:代表多个字符
运算符的优先级从高—低:
\ :转义符
(), (?:), (?=), [] :圆括号和方括号
*, +, ?, {n}, {n,}, {n,m}:限定符
^, $, \anymetacharacter:
| :或 操作
较为常用的元字符:“+”、“*”及“?”
“+”元字符:规定其前导字符必须在目标对象中连续出现1次或多次。如:/fo+/,匹配字符串fo,fool,food,foool,不匹配f
“*”元字符:规定其前导字符必须在目标对象中连续出现0次或多次。如:/fo*/,匹配字符串f,fo,fool
“?”元字符:规定其前导字符必须在目标对象中连续出现0次或1次。如:/fo?/,匹配字符串f,fo,不匹配foo
“{n}”:仅匹配n次。如:0{2},匹配字符串foo/fool/food,不匹配fo,fooo
“{n,}”:至少匹配n次。如:l{2},匹配字符串will,helllp,不匹配wit,it,she
“{n,m}”:至少匹配n次,最多匹配m次
\b:匹配目标字符串的左边界或右边界
\B:匹配目标字符串的左右边界之内的内容
\cX:X的取值范围:A-Z或a-z。如\cM匹配Control-M
\d:匹配0-9的字符
\D:匹配非0-9的字符
\f:匹配换页符
\n:匹配换行符
\r:匹配回车符
\s:匹配任何空白字符,包括空格键、tab键、换行、回车,相当于[\f\\n\r\t\v]
\S:相当于[^\f\\n\r\t\v]
\t:匹配一个制表符
\v:matches a vertical tab character
\w:匹配任何字母、数字和下划线
\W:相当于[^a-zA-Z0-9_]
.:匹配除换行符的所有字符
^:Matches the position at the beginning of the input string. If the RegExp object's Multiline property is set, ^ also matches the position following '\n' or '\r'
$:Matches the position at the end of the input string. If the RegExp object's Multiline property is set, $ also matches the position preceding '\n' or '\r'.