[英]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.