[英]how to extract a certain digit from a String using regular expression in php?
[英]Remove newline character from a digit in the string using PHP regular expression
如何使用 PHP 正则表达式从字符串中删除每个数字前面的换行符?
例子:
$message = "
My Number is \n
0\n
7\n
8\n
9\n
Come Home\n
"
变成:
$message = "
My number is\n
0789\n
Come Home\n
"
这就是我所拥有的,但它删除了所有内容
$message = trim(preg_replace('\d+\s+', '', $message),'\n');
您可以使用此 php 代码:
$message = preg_replace('/(?<=\d)\R+(?=\d)/', '', $message);
如果它后面和前面有一个数字,这将匹配任何换行符的 1+。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.