You might want to check out a tutorial.
If you want to "extract" the number, there is no need for preg_replace
. Use preg_match
or preg_match_all
(if there are multiple occurrences) instead:
preg_match('/\[\[(\d+)\]\]/', $input, $matches);
$integer = $matches[1];
or
preg_match_all('/\[\[(\d+)\]\]/', $input, $matches);
$integerArray = $matches[1];
If instead of "extract" you actually meant something like "how can I preg_replace
this term and use the extracted integer number", you can use the same regular expression and refer to the captured integer, using $1
:
$output = preg_replace('/\[\[(\d+)\]\]/', 'Found this integer -> $1 <-', $input);
Which would result in:
Test Found this integer -> 1294 <- example