以下正则表达式将“Gray”和“James”作为匹配返回。我不明白为什么“名字”不匹配。你能解释一下吗?
"Name: Gray, James"[/(\w+), (\w+)/]
答案 0 :(得分: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
不会使用逗号。
答案 1 :(得分:0)
匹配逗号旁边的单词没有空格“(\ w +),”
匹配逗号和空格后的单词“,(\ w +)”