这个正则表达式应该做什么,因为它一直返回 null?
var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
我以为它是从 rel 属性中提取额外的单词?
谢谢理查德
最佳答案
比赛
facebox // facebox
\[? // [ or nothing
\. // .
(\w+) // word*
\]? // ] or nothing
有效输入:
facebox[.bb
facebox.bb]
facebox[.bb]
facebox.bb
输入无效
facebox[bb]
faceboX[.bb]
Facebox.bb]
<小时/>
关于\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].
引用
关于javascript - 正则表达式不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3947147/