0

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

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

我想我想到了以下几点:

^- 字符的开始

\s*- 零次或多次出现空白

(\*|[\w\-]+)- 我了解\wword 的标准,但我不确定\*and the or|正在评估什么,并且+指定了前面模式的另一个出现。

(?:\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 回答