2012-03-17 12 views
0

私はコードや正規表現のこの行は私だけを見パニック...誰かがこのRegExについて私に説明できますか?

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

誰かがそれが何をするか少しで少し説明していただけますか? おかげで、G

+0

あなた自身とGoogleの各コンポーネントの正規表現を壊すことはできませんか?それはかなり簡単です。 – Blender

+0

私は始めましたが、 '[\ w \ W]'は私には意味がありません。あなたは何が答えを見るのが好奇心。 –

+0

@Blenderあなたは正しいです。実際に私はそれについてMDNで読んでいます。 – Gnijuohz

答えて

2

は、ここで私は抽出することができますものです:

  • ^文字列の先頭。
  • (?:不一致のグループ。
  • [^#<]*#または<以外の任意の連続する文字数。
  • (<[\w\W]+>)<anything_goes_here>のような文字列と一致するグループ。
  • [^>]*>ではない任意の数の文字が連続しています。

|の後の部分は、最初の1が失敗した場合にしようとする第二の正規表現を表します。その一つが#([\w\-]*)です:

  • ##文字に一致します。それほど複雑ではありません。
  • ([\w\-]*)は、任意の数の単語文字またはダッシュに一致するグループです。基本的にはThings-of-this-form
  • $を正規表現の末尾に付けます。

私は正規表現のプロではありませんので、私が間違っている場合は私を修正してください。

+0

私は2つの特殊文字が同時に出現するのに慣れていません。 '\ w \ W'のように、何かにマッチするのではなく、 ?\ w \ - と同じ問題。 – Gnijuohz

+0

物事が '[]'角カッコで囲まれているとき、それらは特定の順序ではありません。 '[] 'は正規表現からのものを含む/除外するために使用されるキャラクタセットを表します(' [az] + 'は' [zyxvutsrqponmlkjihgfedcba] +と同じものに一致します') – Blender

+0

aha ... ' ] '。私は見る...私は馬鹿だ! – Gnijuohz

2
^(?:[^#<]*(<[\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 
+0

あなたの説明はどこですか? –

+1

それはまさに「読書にやさしい」ものではありませんか? – Gnijuohz

+0

これは正規表現が何をしているかを少しずつ伝えています。それはまさにあなたが求めていたものです。 – david

関連する問題