开发者

regex not working

开发者 https://www.devze.com 2023-01-20 00:55 出处:网络
What is this regex supposed to do, because it开发者_如何学C keeps giving back null? var klass = this.rel.match(/facebox\\[?\\.(\\w+)\\]?/)

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

精彩评论

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