Please consider the following string
$text = "Dat foo 13.45 and $600 bar {baz:70} and {8}";
I need to label all numbers in $text, except for when they are between curly braces. I now have this:
preg_replace("/(?<!{)([0-9]+(?:\.[0-9]+)?)(?!})/","{NUMBER:$0}",$text);
which outputs:
Dat foo {NUMBER:13.45} and $ {NUMBER:600} bar {baz: {NUMBER:7} 0} and {8}
However, the desired output is:
Dat foo {NUMBER:13.45} and ${NUMBER:600} bar {baz:70} and {8}
where numbers between { and } are ignored, even if they are surrounded by alfanumerical (or other) characters. In other words – how do I need to adjust the regex to completely ignore whatever there is between curly braces?
Atomic grouping.
And perhaps lookbehind isn’t really needed.