如何select一个以x开头y结尾的子串通过多行替换
how to select a substring that starts with x and ends with y through multilines and replace it
我想找到一个正则表达式,它 select 是一个特定的字符串,该字符串由它的开始和结束字符定义,通过多行,被空字符串替换。假设我有以下字符串:
我想 select 每个以 --
开头并以 ;
结尾的字符串
$str = 'some text --text_to_be_replaced; and another text -- text
to
be
replaced; and some text...;';
我尝试过的:
$str = preg_replace('/--(.*);/s', '', $str);
但返回的结果是:some text
而期望的结果是some text and another text and some text...;
你的正则表达式太贪心了,试试这个:
/--([^;]*);/s
我想找到一个正则表达式,它 select 是一个特定的字符串,该字符串由它的开始和结束字符定义,通过多行,被空字符串替换。假设我有以下字符串:
我想 select 每个以 --
开头并以 ;
$str = 'some text --text_to_be_replaced; and another text -- text
to
be
replaced; and some text...;';
我尝试过的:
$str = preg_replace('/--(.*);/s', '', $str);
但返回的结果是:some text
而期望的结果是some text and another text and some text...;
你的正则表达式太贪心了,试试这个:
/--([^;]*);/s