php regex - 与空间匹配

时间:2014-01-06 17:06:51

标签: php regex

我有一个字符串:

 onchange = "(getURLVar(\'route\') == \'checkout/cart\' || getURLVar(\'route\') == \'checkout/checkout\') ? location = \'index.php?route=checkout/cart&remove=46\' : $(\'#cart\').load(\'index.php?route=module/cart&remove=46\' + \' #cart > *\');

我如何获得*onchange ="...any..."* and *location attrib = location = \'index.php?route=checkout/cart&remove=46\' :*

的价值

使用php正则表达式 ?

1 个答案:

答案 0 :(得分:0)

你的问题有点不清楚,但也许这就是你要找的东西。

$string = 'onchange=\'trueorfalse\'&location=\'index.php?route=checkout/cart&remove=46\'';

preg_match_all("/onchange='([^']+)'[.]*&location='([^']+)'/",$string, $matches);

print_r($matches);

输出:

Array
(
    [0] => Array
        (
            [0] => onchange='trueorfalse'&location='index.php?route=checkout/cart&remove=46'
        )

    [1] => Array
        (
            [0] => trueorfalse
        )

    [2] => Array
        (
            [0] => index.php?route=checkout/cart&remove=46
        )
)