#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    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
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,294
    Rep Power
    9400
    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?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0
    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.
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,294
    Rep Power
    9400
    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 04:47 PM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0
    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.
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,294
    Rep Power
    9400
    Yes. Run that expression against the entire string (assuming the string is exactly what you say it is).
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0
    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.
  14. #8
  15. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,009
    Rep Power
    2791
    I might have missed something here; are you wanting to match everything between the single quotation marks?
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0
    Yes

IMN logo majestic logo threadwatch logo seochat tools logo