very simple regex won't work for me

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

very simple regex won't work for me

Post by mzfp2 »

I'm trying to get the folloinwg reg ex to return a string two parts :

this string would be :

Code: Select all

$string = product_url=name
preg_match_all("#(product_url)=(.*?)#i", $string, $arr_Temp);
Ideally it should return either side of the = in the string as two seperate strings, product_url and name


However the above regex just doesn't seem to return the second part, instead it returns :

Code: Select all

Array
(
    [0] => Array
        (
            [0] => product_url=
        )

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

    [2] => Array
        (
            [0] => 
        )

)

And I just can't figure out why, anyone able to help?

Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Remove the question mark from your expression.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

volka wrote:Remove the question mark from your expression.
Or give it somewhere to end, such as '$'.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

If it must have data after the '=' use '+' instead of '*'
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

Code: Select all

list($url, $name) = explode('=', $string);
;)
Post Reply