I want to change the id partner=852501
to partner=985412
in my code, but stuck in this step. Example:
http://a-ads.com/?partner=852501
My attempt:
([1-z0-9\/]+)\/\/(a-ads\.com\/?)
How to do the right thing?
I want to change the id partner=852501
to partner=985412
in my code, but stuck in this step. Example:
http://a-ads.com/?partner=852501
My attempt:
([1-z0-9\/]+)\/\/(a-ads\.com\/?)
How to do the right thing?
Regex: partner=\K[^&]+
Details:
\K
resets the starting point of the reported match[^&]+
Match a single character not present in the list &
one and unlimited timesPHP code:
preg_replace('/partner=\K[^&]+/', '985412', $url);
preg_replace you can replace the value
$string = 'http://a-ads.com/?partner=852501';
$your = 985412;
echo preg_replace('/(\d+)/', $your, $string);
UPD: The value can be obtained with the help of preg_match
preg_match('/partner=(\d+)/', $string, $match);
echo $match[1];