0

On http://regexstorm.net/tester i use the following pattern:

(?:(?!\(|\)|\,).)*(?:(?:(?'open'\()(?:(?!\(|\)).)*)+((?'content-open'\))(?:(?!\(|\)|\,).)*)+)*(?(open)(?!))

And the following value:

(asi(de, fghdfh(fghjgh))),(dfgsdg)
rtyerty,
dhggjkmf,
bnmvbm,
cvbngfh,
iopuip

And every other match for me is empty. It works correctly if you switch the first * to a +, but i need it to be a *, because there doesn't have to be any characters before the balanced-group. I know that i can just ignore the empty matches, but it is kind of annoying to me and i am wondering if there may be something wrong with my pattern?

Is there a specific character or anchor that is getting matched that i can throw into a [^...] group to use instead of the initial .?

maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37

1 Answers1

0

I think you suffer from overlapping alternate matches:
I've tried to simplify the pattern. I am not fully there (and I hope I have not removed too much) but this should be already an improvement:

(?:[^(),])*(?:(?:(?<open>\()(?:[^()])*)+|((?<content-open>\))(?:[^(),])*))*

Either way, if your pattern does what you want stick with it.

wp78de
  • 18,207
  • 7
  • 43
  • 71