繁体   English   中英

有人可以向我解释此正则表达式吗?

[英]Can somebody explain this RegEx to me?

我看到这行代码和正则表达式让我感到恐慌...

quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/

有人可以一点一点解释它的作用吗? 谢谢,G

^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)

Assert position at the start of the string «^»
Match the regular expression below «(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)»
   Match either the regular expression below (attempting the next alternative only if this one fails) «[^#<]*(<[\w\W]+>)[^>]*$»
      Match a single character NOT present in the list "#<" «[^#<]*»
         Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
      Match the regular expression below and capture its match into backreference number 1 «(<[\w\W]+>)»
         Match the character "<" literally «<»
         Match a single character present in the list below «[\w\W]+»
            Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
            Match a single character that is a "word character" (letters, digits, etc.) «\w»
            Match a single character that is a "non-word character" «\W»
         Match the character ">" literally «>»
      Match any character that is not a ">" «[^>]*»
         Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
      Assert position at the end of the string (or before the line break at the end of the string, if any) «$»
   Or match regular expression number 2 below (the entire group fails if this one fails to match) «#([\w\-]*)$»
      Match the character "#" literally «#»
      Match the regular expression below and capture its match into backreference number 2 «([\w\-]*)»
         Match a single character present in the list below «[\w\-]*»
            Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
            Match a single character that is a "word character" (letters, digits, etc.) «\w»
            A - character «\-»
      Assert position at the end of the string (or before the line break at the end of the string, if any) «$»


Created with RegexBuddy

这是我可以提取的内容:

  • ^字符串的开头。
  • (?:不匹配的组。
  • [^#<]*任何非#<的连续字符。
  • (<[\\w\\W]+>)与诸如<anything_goes_here>类的字符串匹配的组。
  • [^>]*序列中任意多个不是>的字符。

|后的部分 表示如果第一个正则表达式失败,则尝试第二个正则表达式。 那是#([\\w\\-]*)

  • ##字符匹配。 没那么复杂。
  • ([\\w\\-]*)是与任意数量的单词字符或破折号匹配的组。 基本上Things-of-this-form
  • $标志正则表达式的结尾。

我不是regex专业人士,所以如果我写错了,请纠正我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM