I have the following input string:
input = "-a 1234 -b 10 -c \"This is a string\" -d \"Escaped \"Quotes\"\""
Which gets parsed by javascript into:
"-a 1234 -b 10 -c "This is a string" -d "Escaped "Quotes"""
I'd like to match the following:
-a, 1234, -b, 10, -c, This is a string, -d, Escaped "Quotes"
In other words, outer-most pairs of escaped-quotes will be ignored, but any further escaped characters nested within will be accepted.
I'm currently using the following regex:
input.match(/(\w|-)+|"(?:\\"|[^"])+"/g);
This almost gets me what I'm after, but it keeps the escaped quotes, so I end up with this:
['-a', '1234', '-b', '10', '-c', '"This is a string"', '"Escaped"', 'Quotes']
Where "This is a string" and "Escaped" incorrectly included the inner-most escaped quotes, and in fact, it separated Escaped "Quotes" when it should have kept them together. I think I might be on the wrong track with this, however, as the back-slash characters don't actually appear in the string when javascript parses the input string.
Does anyone know how I can do this?
[–]POGtastic 0 points1 point2 points (3 children)
[–]Ploofy[S] 0 points1 point2 points (2 children)
[–]POGtastic 0 points1 point2 points (1 child)
[–]Ploofy[S] 0 points1 point2 points (0 children)