开发者

regex not working

What is this regex supposed to do, because it开发者_如何学C keeps giving back null?

var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)

I thought it was extracting extra words from the rel attribute?

thanks, Richard


Matches

facebox   // facebox
\[?       // [ or nothing
\.        // .
(\w+)     // word*
\]?       // ] or nothing

Valid inputs:

facebox[.bb
facebox.bb]
facebox[.bb]
facebox.bb

Invalid inputs

facebox[bb]
faceboX[.bb]
Facebox.bb]

About \w *

Matches any word character. Equivalent to the Unicode character categories [\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}]. If ECMAScript-compliant behavior is specified with the ECMAScript option, \w is equivalent to [a-zA-Z_0-9].

Reference

  • RegExLib.com Regular Expression Cheat Sheet
  • Regular Expressions Reference - Basic Syntax
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜