.net - Regex to match escapable strings? -


i wrote regex match strings:

(?>(?<quote>""|').*?(?<!\\)\k<quote>) 

i.e., text enclosed in quotes. supports escaping, match "hello\"world" in entirety without stopping @ first quote, want. forgot double-escaping. "hello\\"world" not valid, example.

i'm pretty sure possible fix balancing groups, i've never used them before. know how write this?

regular expressions not meant used escaped constructs.

i don't think it's possible in "nice" kind of way (if @ all), although i'll post edit if figure out otherwise.

balancing group definitions nested constructs. nesting doesn't happen in strings, balancing group definitions don't seem right tool this.


edit 1:

it depends on how many features you're looking for. if want match next escaped quotation, can use pattern

^"([^\\\"]|\\.)*" 

which, when escaped code, turns out like

"^\"([^\\\\\\\"]|\\\\.)*\"" 

to match like

"hello! \" hi! \" " 

but start adding more complicated requirements unicode escapes, becomes lot more tedious. hand, should simpler.


edit 2:

if you're curious how balancing group definitions work anyway, recommend reading page 430 of this book (34 in pdf).


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -