这是我的专栏title
132 lorem ipsum...
21-2 gold sky...
325/1 blue river...
420 health and food
right decision
... and so on.许多标题以不同的整数开头,有时整数被/或-除以;
我怎样才能把它们全部修剪,只得到字母表部分,即:
lorem ipsum...
gold sky...
blue river...
health and food
right decision谢谢。
发布于 2018-10-10 14:34:54
我们可以尝试在这里使用preg_replace删除首字母数字、正斜杠或破折号,然后是可选的空格:
$input = "132 lorem ipsum...\n21-2 gold sky...\n325/1 blue river...\n100 420 health and food\nright decision";
$output = preg_replace("/(?<=^|\n)[0-9\/ -]+/", "", $input);
echo $output;
lorem ipsum...
gold sky...
blue river...
health and food
right decision
注意,这个答案对于一个包含数字的多个术语的行是健壮的,例如,100 420 health and food变成了health and food。
发布于 2018-10-10 14:33:18
您可以使用替换()和(^\d+)作为模式。
$str = "123 Lorem Ipsum";
$cleared = preg_replace("(^\d+)", "", $str);
echo $cleared; //will echo Lorem Ipsumhttps://stackoverflow.com/questions/52742557
复制相似问题