Kristian
Kristian

Reputation: 21810

Why is regex failing on already-escaped quotes?

I am using the following regex:

$regex = "/Built upon the <a href=\"[^>]+banshee-php\\.org/\">[a-z]+<\/a>(?:v([\\d.]+))?\\;version:\\1/U";

And i'm running it against the markup of a typical webpage using preg_match but its dying at a quotation mark.

preg_match(): Unknown modifier '"'

Since all of the quotes are already escaped, I'm not sure why its not running.

Upvotes: 1

Views: 66

Answers (1)

anubhava
anubhava

Reputation: 784998

You can avoid all the escaping by choosing a different regex delimiter and using single quotes around your string like this:

$re='~Built upon the <a href="[^>]+banshee-php\.org/">[a-z]+</a>(?:v([\d.]+))?\\;version:\1~U';

Upvotes: 2

Related Questions