评估正则表达式/ ^ \ s *(\ * | [\ w \ - ] +)(?:\ b | $)?/ i

时间:2012-05-29 03:58:33

标签: regex

我需要一些帮助来评估某些代码中的正则表达式。我正在尝试评估正则表达式

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

我想我想到了以下内容:

^ - 角色的开头

\s* - 出现零个或多个空格

(\*|[\w\-]+) - 我理解\w单词的标准,但我不确定\*|正在评估的内容以及+指定的内容再多出现前一种模式。

(?:\b|$)? - 我需要帮助理解这一点和整个表达方式。

i - 忽略大小写

有些人可以帮助我理解(?:\b|$)?正在评估的内容以及整个表达式吗?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分: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.
相关问题