• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Topic: Regex problem for pattern and grouping

 
Donald Fung
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Donald Fung
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic