Monday, 15 July 2013

php - How Do I Match Square Bracket As A Literal Character Expression? -



php - How Do I Match Square Bracket As A Literal Character Expression? -

i've next code:

<?php // $content = lots of content here preg_match('/token: \'(.*?)\'/', $content, $token); print_r($token); // works charm. preg_match_all("/params\['au' + 'thkey'\] = (.*?);/", $content, $match2); print_r($match2); // returns blank array.

after checking everything, came solution there problem escaping. help me out? think square brackets?

ps: original text regex params['au' + 'thkey'] = texthere;

the problem +. need escape mean literal + \+ or otherwise repeat previous character 1 or more times.

params\['au' \+ 'thkey'\] = (.*?);

demo

code:

preg_match_all("~params\['au' \+ 'thkey'\] = (.*?);~", $content, $match2);

php regex

No comments:

Post a Comment