March 25th, 2010, 12:41 PM
-
Regular expression, any suggesion
The regular expression is:
(?i)IS_HOLIDAY\('(.*?)'(?
?:,\s*'((?:\s*\w+)+)')*)\)
I try to parse :
IS_HOLIDAY('10/01/2009','CAD', 'us holiday', 'test')
and I want to get
Group 1 : 10/01/2009
Group 2 : CAD
Group 3 : us holiday
Group 4 : test
however I got
Group 1 : 10/01/2009
Group 2 : test
How to modify upper expression, any suggestion? thanks
March 25th, 2010, 01:41 PM
-
The second big subexpression doesn't account for multiple arguments.
You can't get a varying number of matches back. I'd grab what's in the parentheses and then do a match on that for anything that looks like an argument.
What language are you using?
March 25th, 2010, 02:00 PM
-
Originally Posted by requinix
The second big subexpression doesn't account for multiple arguments.
You can't get a varying number of matches back. I'd grab what's in the parentheses and then do a match on that for anything that looks like an argument.
What language are you using?
I use JAVA.
I could use Expression like : (?i)IS_HOLIDAY\('(.*?)'((?:,\s*'(?:\s*\w+)+')*)\)
So The Group 2 I will get like : ,'CAD', 'us holiday', 'test', then parse it using JAVA.
But this way looks not that good.
March 25th, 2010, 03:38 PM
-
Actually, I lie. Try this.
Code:
(?<=IS_HOLIDAY\(|,)\s*('(?:\\.|[^'])*'|"(?:\\.|[^"])*"|[^'",)]+)
Match that against the entire string and grab the [1]s.
Last edited by requinix; March 25th, 2010 at 03:47 PM.
March 25th, 2010, 04:01 PM
-
Thanks for your prompt reply. but I am really confused, is that match upper sentence (IS_HOLIDAY('10/01/2009','CAD', 'us holiday', 'test'))? could you explain a little.
March 25th, 2010, 05:24 PM
-
Yes. Run that expression against the entire string (assuming the string is exactly what you say it is).
March 25th, 2010, 06:46 PM
-
I test it using The Regex Coach, looks like it doesn't work.
I use (?i)IS_HOLIDAY\('([^']*)','((?:[^',]+|'|,)*)'\) to check the sentence, and using '\s*,\s*' to split the group(2). any way, it is working.
Thanks again.
March 25th, 2010, 07:16 PM
-
I might have missed something here; are you wanting to match everything between the single quotation marks?
March 26th, 2010, 10:28 AM
-