parsing quotes in match function

Post your questions and help other users.

Moderator: Martin

Post Reply
Ruffman
Posts: 1
Joined: 19 Jan 2014 14:50

parsing quotes in match function

Post by Ruffman » 19 Jan 2014 15:00

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.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: parsing quotes in match function

Post by Martin » 19 Jan 2014 17:02

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

Post Reply