PHP preg_match() tests a string against a PCRE regular expression and can return captured groups.
Code examples
if (preg_match('/user_(\d+)/', 'user_42', $matches)) {
echo $matches[1];
}
Find every match:
preg_match_all('/user_(\d+)/', 'user_42 user_99', $matches);
Common errors
Escape delimiters inside patterns, and remember that advanced PCRE features may not behave like JavaScript regex.
Related tool
Try the PHP Regex Tester.