1

以下正则表达式返回“Gray”和“James”作为匹配项。我不明白为什么“名称”不匹配。你可以解释吗?

"Name:  Gray, James"[/(\w+), (\w+)/]
4

2 回答 2

3

这是您的正则表达式如何工作的解释

Match the regular expression below and capture its match into backreference number 1 «(\w+)»
   Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the characters “, ” literally «, »
Match the regular expression below and capture its match into backreference number 2 «(\w+)»
   Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»

格雷,詹姆斯
(\w+), (\w+)

Name不跟逗号。

于 2012-10-12T01:29:11.203 回答
0

匹配逗号旁边的单词没有空格“(\w+),”

匹配逗号和空格 ", (\w+)" 后的单词

于 2012-10-12T01:32:24.663 回答