[英]php regexp how to delete strings after substring
I have problem with regex. 我对正则表达式有疑问。 Trying to delete a strings in text started with "(chapter 1)" constractions, but it does't work.
试图删除以“(第1章)”开头的文本中的字符串,但它不起作用。
$line = preg_replace('/(\(chapter.*$/', '', $line);
Text for sample: 样本文字:
(charter 1)sample text, sample text.
(charter 2)sample text, sample text.
(charter 3)sample text, sample text.
$str = "(charter 1)sample text, sample text.";
$str = preg_replace("#^\(charter \d*\)#", "", $str);
// output: sample text, sample text.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.