[英]Split a string on a pattern
var a="##55##data1!!##66##data4545!!##77##data44!!";
how to remove ##664545##data!! 如何删除## 664545 ## data !! from the string
从字符串
Edit:if we know the start value in a string ie,##66## and the end value ie,!! 编辑:如果我们知道字符串中的起始值即## 66 ##,而结束值即!!
In the main string how to remove characters starting from the start pattern,data after the start pattern till the end pattern 在主字符串中如何从开始模式开始删除字符,从开始模式之后到结束模式的数据
My expected output will be ##55##data1!##77##data44!!
Using javascript and regex - 使用javascript和regex-
a.replace(/##66##[a-zA-Z0-9]*!!/g,"")
If you want to parameterize this then you can do as given below where start and end are your parameters- 如果要对此进行参数化,则可以按照以下给出的步骤进行操作,其中start和end是您的参数-
var a = "##55##data1!!##66##data4545!!##77##data44!!";
var start = "##66##";
var end = "!!";
var re = new RegExp(start + "[a-zA-Z0-9]*" + end, "g");
return a.replace(re,"");
正则表达式的方式,用全局标志g
来捕获所有匹配项:
a.replace(/##66##data!!/g,"")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.