
Regexp to match a C-style string
Hi all
I need to create a text file format which holds strings. The strings can
legally contain any ASCII character, so they must be encoded in some way.
C-style would be most convenient. Some example records might be:
ITEM foo="a string" bar="a string containing \"quotes\""
ITEM baz="a string ending with a slosh: \\"
ITEM qux="a string ending with a slosh and a quote: \\\""
Anyone know of a regexp that can find the limits of a string, and won't be
tripped up by combinations of escaped quotes and escaped sloshes?
My current effort is:
/".*?(?<!\\)(\\\\)*"/
The idea is to find the nearest quote which is preceded by an even number
of sloshes (including 0). Nice in theory, but unfortunately, it doesn't
seem to work.
Cheers
- rog