Skip to content
Advertisement

Regex PHP – Get specific text including new lines and multiple spaces

I was trying to get the text starting from css:{(some text…)} up to the ending bracket only, not including the texts below in another text file using php.

test.sample

JavaScript

I’m using vscode/sublime search and replace tool to test my regex syntax and nothing is wrong, I successfully get the text that I want including all the new lines and spaces inside, but when i tried to apply it on php, the regex that I created doesn’t work, it cannot find the text that im looking for.

here is my code:

myphp.php

JavaScript

This is my regex that I just created.

(csss*n*:s*n*{s*n*)+((.|nS)|(.|ns))(n*)(}W)$

Please help me, Im open for any suggestion, Im a newbie on regular expression, Im lacking on knowledge about the logic of it.

thanks.

Advertisement

Answer

Hey guys I found the solution! base on the answer of @alex

Dont really know if I am implementing this right.

Here is my code

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement