Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2007

Tip: Looking for answers? Try searching our database.

Grouping Regex question

Thread view: 
gill.jp@gmail.com - 29 Jan 2007 21:42 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.