以下正則表達式返回「Gray」和「James」作爲匹配項。我不明白爲什麼「名稱」不匹配。你可以解釋嗎?Reg表達式:爲什麼「名稱」不作爲匹配返回
"Name: Gray, James"[/(\w+), (\w+)/]
以下正則表達式返回「Gray」和「James」作爲匹配項。我不明白爲什麼「名稱」不匹配。你可以解釋嗎?Reg表達式:爲什麼「名稱」不作爲匹配返回
"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
不遵循逗號。
謝謝,你從哪裏得到了解釋。它看起來像是由程序生成的。 – BrainLikeADullPencil
匹配旁邊一個字一個逗號沒有空格「(\ w +),」
匹配一個逗號和空格後一個字「(\ w +)」
因爲你的正則表達式匹配兩個詞用逗號和空格隔開 –