上面這個網站能夠用於在線檢測JS的正則表達式語法正則表達式
除了熟知的幾個固定字符表示位置:網站
^ : Match the beginning of the string and, in multiline searches, the beginning of a line.ui
$ : Match the end of the string and, in multiline searches, the end of a line.url
\b: spa
Match a word boundary. That is, match the position between a \w character and a \W character or between a \w character and the beginning or end of a string. (Note, however, that [\b] matches backspace.)regexp
\B: Match a position that is not a word boundary.blog
還有的就是使用正則表達式來肯定要匹配的位置,也叫作Zero-Width Test(零寬斷言)get
(?=p) :string
p
(?!p) :it
A negative lookahead assertion. Require that the following characters do not match the pattern p.
對於(?=p)和(?!p)的使用舉一個例子:
要在url(skins/default/images/index/default.png)中匹配"/default/"中的"default",而不匹配"/default.png"中的"default"?
正則表達式: (?!\/)default(?=\/)
其中(?!\/)表示以"/"開頭,(?=\/)表示以"/"結尾