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.
Re: Regex match strings between , only when outside of complete brackets
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.
Re: Regex match strings between , only when outside of complete brackets
Empyreal, you wouldnt happen to be Ms Empyreal off RS would you?
Re: Regex match strings between , only when outside of complete brackets
Sorry, no; I'm not even sure what "RS" is. What is it?
Re: Regex match strings between , only when outside of complete brackets
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