Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java regular expression

Tags:

java

regex

I am trying to write a regular expression for somethin like

s1 = I am at Boston at Dowtown
s2 = I am at Miami

I am interested in the words after at eg: Boston, Downtown, Miami

I have not been successful in creating a regex for that. Somethin like

> .*? (at \w+)+.*

gives just Boston in s1 (Downtown is missed). it just matches the first "at" Any suggestions

like image 385
BSingh Avatar asked Jan 21 '23 22:01

BSingh


1 Answers

Try this

 at\s+(\w+)

The complete code snippet would be

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);
}
like image 171
arclight Avatar answered Feb 01 '23 17:02

arclight