preg_replace 包含垂直 line/pipe 字符的字符串
preg_replace a string that contains vertical line/pipe character
我有这样的字符串:
$str1="YESYES|c|no|c|";
$str2="YESYES|c|not this|c|YES|c|or this|c|";
$str3="YES";
我想要这样的字符串:
$str1="YESYES";
$str2="YESYESYES";
$str3="YES";
我以为我可以使用 preg_replace 但事实上我正在看一个管道似乎会造成麻烦,如果我这样做的话:
$i=preg_replace("//|c\|[\s\S]+?/|c\|/",'',$i);
我收到 'unknown modifier "|"' 错误。我知道这一定是以前问过的,但很难搜索。正确的正则表达式是什么?
您必须使用下一行:
$i=preg_replace("/\|c\|[\s\S]+?\|c\|/",'',$i);
这与您所拥有的几乎相同,但使用 \ 而不是 / 来对管道进行换码
我有这样的字符串:
$str1="YESYES|c|no|c|";
$str2="YESYES|c|not this|c|YES|c|or this|c|";
$str3="YES";
我想要这样的字符串:
$str1="YESYES";
$str2="YESYESYES";
$str3="YES";
我以为我可以使用 preg_replace 但事实上我正在看一个管道似乎会造成麻烦,如果我这样做的话:
$i=preg_replace("//|c\|[\s\S]+?/|c\|/",'',$i);
我收到 'unknown modifier "|"' 错误。我知道这一定是以前问过的,但很难搜索。正确的正则表达式是什么?
您必须使用下一行:
$i=preg_replace("/\|c\|[\s\S]+?\|c\|/",'',$i);
这与您所拥有的几乎相同,但使用 \ 而不是 / 来对管道进行换码