I am trying to get all the names i.e: SMITH J , BALTIMORE D, JONES AL
String input = "NAME=(SMITH J) NAME=(BALTIMORE D) NAME=(JONES AL)
JUNK=(ABC);
Pattern pattern = Pattern.compile(" ");
Matcher matcher = pattern.matcher(input);
for (int i=0; i<=matcher.groupCount(); i++) {
String groupStr = matcher.group(i);
System.out.println("groupStr: "+ groupStr);
}
I played around with few patterns, I am unable to get all of the
names.
Anyone knows what this regex might be?
Thanks, J
Carl - 29 Jan 2007 22:15 GMT
On Jan 29, 1:42 pm, gill...@gmail.com wrote:
> I am trying to get all the names i.e: SMITH J , BALTIMORE D, JONES AL
>
[quoted text clipped - 12 lines]
>
> Thanks, J
Something like this should get you started:
Matcher matcher = Pattern.compile("NAME=\\((.*?)\\)").matcher(input);
while(matcher.find()) {
System.out.println(matcher.group(1));
}
Hope that helps,
Carl.
gill.jp@gmail.com - 30 Jan 2007 03:15 GMT
Thanks Carl. Got it to work.