Let’s say you have a string that contains quoted text, and you need to capture that text including escaped quotes. For example, if the escape character is a backslash, let’s say the text is:
Title: "not \"the one\", but the one."
You want to end up with not \"the one\", but the one.
. This pattern will do that:
"((?:\\\"|[^"])+)"
(The quotes are part of the pattern. In Xojo, you’d enter that as """((?:\\\""|[^""])+)"""
.)
It start with the quote then starts a capturing group. Another non-capturing group is started that looks for either the backslash-quote or another character that is not a quote, and that’s repeated one or more times. Finally, the ending quote is captured. The text will be within SubExpressionString( 1 ).
[quote=95921:@Kem Tekinay]Let’s say you have a string that contains quoted text, and you need to capture that text including escaped quotes. For example, if the escape character is a backslash, let’s say the text is:
Title: "not \"the one\", but the one."
You want to end up with not \"the one\", but the one.
. This pattern will do that:
"((?:\\\"|[^"])+)"
(The quotes are part of the pattern. In Xojo, you’d enter that as """((?:\\\""|[^""])+)"""
.)
It start with the quote then starts a capturing group. Another non-capturing group is started that looks for either the backslash-quote or another character that is not a quote, and that’s repeated one or more times. Finally, the ending quote is captured. The text will be within SubExpressionString( 1 ).[/quote]
Awesome Kem and thank you for the tip. RegEx can get complicated fast! 
I have always seen the capture groups but I haven’t used them. Now I am wondering if I should have been 
Normally I would come up with a pattern like this to get the same results. Do you think this way is ok (scalable)?
Note: The pattern is from RegExRx and not Xojo so my quotes are as such.
(?<=").+?(?=")
Thanks!
You are using lookaround there (coincidentally what my latest xDev column covers), and the problem is in properly getting the next match. For example:
"part 1" filler "part 2"
What do you expect to capture? Most likely you want “part 1” and “part 2”, but what you’ll get is “part 1”, " filler ", and “part 2”. Lookarounds don’t advance the internal pointer so the first match will leave the pointer before the final quote, not after it, so it will be counted again.
Also, your pattern doesn’t take into account escaped quotes, but you probably knew that.
[quote=95942:@Kem Tekinay]You are using lookaround there (coincidentally what my latest xDev column covers), and the problem is in properly getting the next match. For example:
"part 1" filler "part 2"
What do you expect to capture? Most likely you want “part 1” and “part 2”, but what you’ll get is “part 1”, " filler ", and “part 2”. Lookarounds don’t advance the internal pointer so the first match will leave the pointer before the final quote, not after it, so it will be counted again.
Also, your pattern doesn’t take into account escaped quotes, but you probably knew that.[/quote]
Wow Kem I am so glad I asked! Thank you for that info!