I have to write an argument parser, it is passed in as a string ala {a, b, c} delimiter is comma with a space after it, but it can be escaped with a pipe "|" before it. So I was thinking of writing a regex like /[^\|], /
to split by, and then removing all the escape characters afterwards. But when using this it will split by the character before the delimiter as well.
How should I go about accomplishing what I'm looking for?开发者_JAVA百科
If you're on version 1.9 of Ruby, you can split on /(?<!\|),/
.
(?<!\|)
is a negative lookbehind assertion meaning "ensure that the previous character is not a |
".
精彩评论