• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Topic: Regex problem for pattern and grouping

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic