Friday, 15 August 2014

regex - Ruby regexp to match comma, but ignore comma in brackets -


I'm trying to divide the parameter list by regexp.

This is a string with my parameter list:

  "a = b, c = 3, d = [1,3,5,7], e, What do I want:  
  ["a = b", "c = 3", "d = [1,3, 5,7] "," E "," f = g "  

I tried with a lookhead, but Ruby does not allow to keep an eye on a dynamic range , So this will not work:

  / (? & Lt;! \ [], (?! \ W * \]) /   

How to Can I tell regexp to ignore everything in square brackets?

Maybe something like this will work for you:

  str.scan (/ (?: \ [ 

would be a simple non greedy matcher. Some cases of nested brackets Failed.

No comments:

Post a Comment