Results 1 to 7 of 7

Thread: Regex match strings between , only when outside of complete brackets

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    70

    Regex match strings between , only when outside of complete brackets

    Hello,

    I am trying to make a regex that will match strings between a comma only if the comma is outside of complete brackets. Brackets inside of " " should not count. Examples below.

    one(1,2),two(3,4)
    should match:
    one(1,2)
    two(3,4)

    test(ok(1,2),2),another(5,testing(3,4))
    should match:
    test(ok(1,2),2)
    another(5,testing(3,4))

    A more complex finale:
    test(check(onemore(ok,4,9),"no"),"(","2","3"),next("forward",ok(34.2),"3,2,5"),last(1,2)

    This should match:
    test(check(onemore(ok,4,9),"no"),"(","2","3")
    next("forward",ok(34.2),"3,2,5")
    last(1,2)

    Thanks in advance.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Regex match strings between , only when outside of complete brackets

    heres a regex tutorial + a regex reference site

  3. #3
    Addicted Member
    Join Date
    Jul 2009
    Posts
    138

    Re: Regex match strings between , only when outside of complete brackets

    After much guessing and checking, I ended up with this:

    Code:
    [a-z]+\(([a-z0-9,."\(]*,[a-z]*\(?[a-z0-9,."\)]*)?\)
    It should work for what you need, but this was a pretty complex regexp, and I'm not a genius.

    Although with one exception; in the last example, you'll get this:

    test(check(onemore(ok,4,9),"no")
    next("forward",ok(34.2),"3,2,5")
    last(1,2)

    This is because there is 4 begin parentheses and 3 close parentheses in this:

    test(check(onemore(ok,4,9),"no"),"(","2","3")

    I don't have time to try and figure something else out.

    I really suggest you try to learn regexp for yourself via the links .paul. gave you. There are also many regexp testers on the internet so you can experiment, which is exactly what I do.

  4. #4
    New Member
    Join Date
    Jul 2009
    Posts
    11

    Re: Regex match strings between , only when outside of complete brackets

    Empyreal, you wouldnt happen to be Ms Empyreal off RS would you?

  5. #5
    Addicted Member
    Join Date
    Jul 2009
    Posts
    138

    Re: Regex match strings between , only when outside of complete brackets

    Sorry, no; I'm not even sure what "RS" is. What is it?

  6. #6
    New Member
    Join Date
    Jul 2009
    Posts
    11

    Re: Regex match strings between , only when outside of complete brackets

    RS = RuneScape.

  7. #7
    Addicted Member
    Join Date
    Jul 2009
    Posts
    138

    Re: Regex match strings between , only when outside of complete brackets

    Oh; anyway, for future notice, if you want to ask someone something that is not related to the thread, please pm them. I realized this AFTER I already sent my message, so I'm guilty too =P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width