SM9 SM9 - 4 months ago 14
PHP Question

preg_replace that ignores a new line?

Sorry for the vague title, but basically I have no idea when it comes to regex, but I need a match for the following:


Basically, I want to ignore all the spaces and new lines, and be able to replace "items" with "items2" only if a { is followed.

Any help would be greatly appreciated.

Edit: I would need it to replace first occurrence only, The idea is to stop any further occurrences overwriting it when I convert it into an array.

The original file is here:



How about:

$str = preg_replace('/"items"(?=\s+\{)/', '"items2"', $str, 1);

\s stands for any white space included linebreak.