This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Topic: Regex problem for pattern and grouping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Topic: Regex problem for pattern and grouping" Watch "Topic: Regex problem for pattern and grouping" New topic
Author

Topic: Regex problem for pattern and grouping

Donald Fung
Greenhorn

Joined: Oct 27, 2004
Posts: 18
Hi everyone,

I have the following statement, "VARCHAR2 (a,2,c)", and the outputs I want are "a" , "2" and "c".

There're two problems.
1) How can I ignore the "VARCHAR2 (" and ")" by using the pattern?
2) Can the extracted "a", "2", "c" in the same group?

I can use subString & split to process it but I'm looking for idea by using pattern to do the same result.
Thanks.

Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
This code will extract all the characters as a group, but the commas are still there. You could use the String.split() method the extract the comma delimited Strings. The regex I came up with presupposes that there will always be at least one comma in the values, no commas outside of the values, but as many values as you want. If these assumptions don't match the actual problem, you'll have to adjust the regex accordingly.
i.e. it will match:
a,b,c
a,b,c,d,e,f
a,
abc,def,ghi

but not:
a
abc


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Donald Fung
Greenhorn

Joined: Oct 27, 2004
Posts: 18
Thanks for your reply.

Finally, I'd updated the pattern to the following to extract the ().
And then I put the result into the matcher agin to get the result.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Topic: Regex problem for pattern and grouping