Ruby Reg表达式:为什么;名称“;未作为匹配项返回

Ruby Reg表达式:为什么;名称“;未作为匹配项返回,ruby,regex,Ruby,Regex,下面的正则表达式返回“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 char

下面的正则表达式返回“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+)


名称
不在逗号后面。

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


在逗号和空格“,(\w+)”之后匹配一个单词。

因为正则表达式匹配两个由逗号和空格分隔的单词。谢谢,你从哪里得到这个解释的。它看起来像是由程序生成的。