You should go with the the following:
/id=(\d+)/g
Explanations:
id=
- Literal id=
(\d+)
- Capturing group 0-9
a character range between 0
and 9
; +
- repeating infinite times
/g
- modifier: global. All matches (don't return on first match)
Example online
If you want to grab all ids and its values in PHP you could go with:
$string = "There are three ids: id=10 and id=12 and id=100";
preg_match_all("/id=(\d+)/", $string, $matches);
print_r($matches);
Output:
Array
(
[0] => Array
(
[0] => id=10
[1] => id=12
[2] => id=100
)
[1] => Array
(
[0] => 10
[1] => 12
[2] => 100
)
)
Example online
Note: If you want to match all you must use /g
modifier. PHP doesn't support it but has other function for that which is preg_match_all
. All you need to do is remove the g
from the regex.