java正则表达式

BSi*_*ngh 4 java regex

我正在尝试为某些东西写一个正则表达式

s1 = I am at Boston at Dowtown
s2 = I am at Miami
Run Code Online (Sandbox Code Playgroud)

我对以下的话感兴趣:例如:波士顿,市中心,迈阿密

我没有成功为此创建一个正则表达式.有些喜欢

> .*? (at \w+)+.*
Run Code Online (Sandbox Code Playgroud)

在s1给出了波士顿(错过了市中心).它只匹配第一个"at"任何建议

arc*_*ght 7

试试这个

 at\s+(\w+)
Run Code Online (Sandbox Code Playgroud)

完整的代码片段将是

Pattern myPattern = Pattern.compile("at\\s+(\\w+)", Pattern.DOTALL, Pattern.CASE_INSENSITIVE);
Matcher m = myPattern.matcher(yourString);

while(m.find()) {
  String word = m.group(1);
}
Run Code Online (Sandbox Code Playgroud)