0

いくつかのコードで正規表現を評価するのに助けが必要です。正規表現を評価しようとしています。

/^\s*(\*|[\w\-]+)(?:\b|$)?/i

私は次のことを考えたと思います:

^-キャラクターの始まり

\s*-空白の発生が0回以上

(\*|[\w\-]+)\w-単語の基準は理解していますが、何を評価しているのか\*、または|が評価しているのかわかりません+。また、前のパターンのもう1つの出現を指定します。

(?:\b|$)?-これと表現全体を理解するのに助けが必要です。

i-大文字と小文字を区別しない

(?:\b|$)?何を評価しているのか、そして表現全体を理解するのに役立つ人がいますか?どんな助けでもいただければ幸いです。

4

1 に答える 1

2
/                # Start regex delimiter.
^                # Anchor to start of string.
\s*              # Match 0 or more whitespace (\s) characters.
(\*|[\w\-]+)     # Alternation between a literal `*` and one or more word
                 # characters (\w) or a dash (needlessly escaped). Store in
                 # capturing group 1.
(?:\b|$)?        # Create a non capturing alternation between a word boundary
                 # or the end of the string. This entire alternation is 
                 # optional.
/                # End regex delimiter.
i                # Make the regex case insensitive. Needless here as there is 
                 # no literal alphabetical characters used.
于 2012-05-29T04:03:28.267 に答える