以下正则表达式返回“Gray”和“James”作为匹配项。我不明白为什么“名称”不匹配。你可以解释吗?
"Name: Gray, James"[/(\w+), (\w+)/]
这是您的正则表达式如何工作的解释
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
不跟逗号。
匹配逗号旁边的单词没有空格“(\w+),”
匹配逗号和空格 ", (\w+)" 后的单词