Let’s say I have the string: "Test [[1294]] example"
How could I do a preg_replace() that would extract the number from the double brackets?
What is the (greedy) expression for getting that number? -it’ll always be a integer within double brackets.
You might want to check out a tutorial.
If you want to “extract” the number, there is no need for
preg_replace. Usepreg_matchorpreg_match_all(if there are multiple occurrences) instead:or
If instead of “extract” you actually meant something like “how can I
preg_replacethis term and use the extracted integer number”, you can use the same regular expression and refer to the captured integer, using$1:Which would result in: