Regex negative lookbehind in Ruby doesn't seem to work

前端 未结 1 1475
抹茶落季
抹茶落季 2021-01-18 06:15

Making an argument parser. I want to split a string into an array where the delimiter is \", \" except when preceded by \"|\". That means string

1条回答
  •  被撕碎了的回忆
    2021-01-18 07:06

    Ruby's regex engine doesn't support lookbehind (yet).

    You'd need to switch to 1.9 or use Oniguruma.


    If that's not an option, you can search for |, and replace it with some sort of marker. After all is said and done, put the |, back.

    You can also try a regex like:

    /(?:[^|]), /
    

    But obviously the (?:[^|]) is not zero-width, which means you'll need to do some extra work afterwards.

    0 讨论(0)
提交回复
热议问题