Regex: delete all text inside double quotes (including multi-line)

It is difficult for me to remove the text in double quotes, especially those that spread over several lines:

$file=file_get_contents('test.html');

$replaced = preg_replace('/"(\n.)+?"/m','', $file);

I want to remove ALL text in double quotes (included). Some texts inside them will be spread over several lines.

I read that new lines may be \r\nand \n.

+3
source share
6 answers

Try the following expression:

"[^"]+"

Also make sure you replace globally (usually with a flag g- my PHP is rusty, so check the docs).

+5
source

: daalbert : , , .

, HTML: 0 ... :

"[^"]*"

EDIT:

, :

"[\S\s]*?"

: ", , , , "

, ... , , char... : " - char, char":) - , - .


, , :

"(.*?(\s)*?)*?"

:

: ( , , , , ),

, . , , . , , .

regex: http://www.regular-expressions.info
: http://regexpal.com/

, , .

+2

( dotall), ( , ):

/".+?"/s

, ^ $ / / . .

0

"[^"]+"

0

- . s - dotall, . :

/".+?"/s
0
$replaced = preg_replace('/"[^"]*"/s','', $file);

will do it for you. However, note that it will not allow the use of any quoted double quotes (for example, it A "test \" quoted string" Bwill result in A quoted string" Ba leading space, not in A B, as you might expect.

0
source

All Articles