Reputation: 111
Sorry for the vague title, but basically I have no idea when it comes to regex, but I need a match for the following:
https://fragdeluxe.com/api/csgo_schema.php
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: https://raw.githubusercontent.com/SteamDatabase/GameTracking/master/csgo/csgo/scripts/items/items_game.txt
Thanks.
Upvotes: 0
Views: 315
Reputation: 91385
How about:
$str = preg_replace('/"items"(?=\s+\{)/', '"items2"', $str, 1);
\s
stands for any white space included linebreak.
Upvotes: 4