Page 1 of 1

parsing quotes in match function

Posted: 19 Jan 2014 15:00
by Ruffman
I cannot use the match function if I try to escape doubles quotes with backslashes.
example:
".*?input type=/"hidden/" value=/"([0-9a-f]+?)/" name=/"csrf/".*"
everything gets weired after the second double quote.

Re: parsing quotes in match function

Posted: 19 Jan 2014 17:02
by Martin
Hi,

Double quotes in a string should be escaped using a backslash, not a forward slash:
s = ".*?input type=\"hidden\" value=\"([0-9a-f]+?)\" name=\"csrf\".*";

You can also use single-quotes to enclose the string. This has the advantage that double quotes don't need to be escaped (and it avoids that inline-expressions in string literals like {a} are replaced, which could be used in some regular expressions):
s = '.*?input type="hidden" value="([0-9a-f]+?)" name="csrf".*';

Regards,
Martin