正则表达式:删除“双引号"中的所有文本;(包括多行) [英] regex: remove all text within "double-quotes" (multiline included)

查看:110
本文介绍了正则表达式:删除“双引号"中的所有文本;(包括多行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难删除双引号内的文本,尤其是那些分布在多行上的文本:

I'm having a hard time removing text within double-quotes, especially those spread over multiple lines:

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

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

我想删除双引号内的所有文本(包括在内).其中的一些文本将分布在多行中.

I want to remove ALL text within double-quotes (included). Some of the text within them will be spread over multiple lines.

我读到换行符也可以是 \r\n\n.

I read that newlines can be \r\n and \n as well.

推荐答案

试试这个表达式:

"[^"]+"

还要确保全局替换(通常使用 g 标志 - 我的 PHP 生锈了,所以请查看文档).

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

这篇关于正则表达式:删除“双引号"中的所有文本;(包括多行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆