Can anyone help me with finding regular expression for the below
$string = "id=A12dk9-mds&name=4950";
I need to find regular expression to find a dynamic value (A12dk9-mds
in this example).
i.e the dynamic content between =
and &
Can anyone help me with finding regular expression for the below
$string = "id=A12dk9-mds&name=4950";
I need to find regular expression to find a dynamic value (A12dk9-mds
in this example).
i.e the dynamic content between =
and &
A simple regex can be used for that.
/id=([^&]*)&/
Explanation:
id=
matches id=([^&]*)
matches anything but the & symbol as much as possible and returns that&
matches the &As long as you know they will always be between a =
and a &
this will work.
PHP Code:
$string = "id=A12dk9-mds&name=4950";
preg_match('/id=([^&]*)&/',$string, $answer);
print_r($answer[1]);