正则表达式 – 这是什么意思?使用表达式匹配什么字符串?

前端之家收集整理的这篇文章主要介绍了正则表达式 – 这是什么意思?使用表达式匹配什么字符串?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我查看了sizzle代码并查看了一个定义.

var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,

我想知道如何找出这个正则表达式匹配的字符串?

解决方法

请参见 this article.多行正则表达式中的说明:

var chunker = /
 (
  (?:
   # One or more sets of parentheses that contain a string,or another set of 
   parentheses with a string
   \(
   (?:
    \([^()]+\)
    |
    [^()]+
   )+
   \)
   |
   # Or one or more sets of brackets that contain a string,or another set of
   brackets with a string
   \[
   (?:
    \[[^\[\]]*\]
    |
    ['"][^'"]*['"]
    |
    [^\[\]'"]+
   )+
   \]
   |
   # Or a backslash followed by any character
   \\.
   |
   # Or one or more of any except these characters: > +~,([\
   [^ >+~,(\[\\]+
  )+
  # or any one of these characters: >+~
  |
  [>+~]
 )
 # followed by zero or one commas,which may be surrounded by whitespace
 (\s*,\s*)?
 # followed by zero or more of anything,including line endings
 ((?:.|\r|\n)*)
/g

此表达式包含三个匹配组:“已验证”选择器表达式,最终逗号以及之后的所有内容.它将在选择器上连续调用以将其分成几部分,有关详细信息,请参阅Sizzle构造函数.

猜你在找的正则表达式相关文章