我需要正则表达式,它会.在数字之后立即逃脱。
1. Something->1\. Something
这将用于避免将该行格式化为有序列表。
任何数字 -\d
任何计数 -+
点 -\.
可以在这里找到更多解释 和preg_replace文档
所以它可能是那样的
<?php
$string = '1. Something 2. Something 3.Something';
$pattern = '/(\d+)\./';
$replacement = '${1}\.';
echo preg_replace($pattern, $replacement, $string);
我刚刚尝试了以下代码,并按照您的要求工作
$re = '/([0-9]+)\s*(\.\s*)/m';
$str = '1. 2. 3.
1. text1 1.text 1 . test
1.next line';
$subst = '';
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;