写一个正则替换,替换字符串中的,,||字符为空格
发布网友
发布时间:2022-04-23 05:23
我来回答
共2个回答
热心网友
时间:2022-04-23 06:52
<?php
$str = ' 河北,石家庄,北京,上海|天津|||重庆|保定,,,河南 ';
$str = preg_replace("/([ ,,||]+)/u", " ", $str);
$str = ltrim(rtrim($str));
print_r($str);
?>
热心网友
时间:2022-04-23 08:10
<script language="javascript">
var str=" 河北,石家庄,北京,上海|天津|||重庆|保定,,,河南 ";
str=str.replace(/^\s*/,"");
str=str.replace(/\s*$/,"");
str=str.replace(/[,\|]+/g," ");
str=str.replace(/|/g," ");
str=str.replace(/,/g," ");
document.write(str);
</script>这个是javascript
<%
dim str
str=" 河北,石家庄,北京,上海|天津|||重庆|保定,,,河南 "
str=trim(str)
str=replace(str,","," ")
str=replace(str,","," ")
str=replace(str,"|"," ")
str=replace(str,"|"," ")
response.write str
%>