我有一个字符串数组:
"Turn <b>left</b> onto <b>Capitol Ave SW</b>"
"Head <b>east</b> toward <b>Browder St</b>"
"Merge onto <b>I-20 E</b><div style=\"font-size:0.9em\">Passing through Louisiana</div><div style=\"font-size:0.9em\">Entering Mississippi</div>" string
"Keep <b>right</b> at the fork to continue on <b>I-20 E</b>/<b>US 49 S</b>, follow signs for <b>Hattiesburg</b>/<b>Meridian</b><div style=\"font-size:0.9em\">Continue to follow I-20 E</div><div style=\"font-size:0.9em\">Entering Alabama</div>"
"Merge onto <b>I-20 E</b><div style=\"font-size:0.9em\">Passing through Georgia, South Carolina</div>"
我需要获得子串“通过X,Y”和“进入Z”。 所以,我需要得到所有州:)
更新:
此模式有效:
Passing though [A-Za-z, ]+
答案 0 :(得分:1)
将我的评论翻译成答案。
以下正则表达式适合您:
\b(?:Passing thr?ough|Entering) ([A-Za-z, ]+)
问题是城市名称前缺少空格而城市名称模式中没有量词。