在模式上分割字符串

发布于 2024-09-24 18:03:17 字数 287 浏览 0 评论 0原文

   var a="##55##data1!!##66##data4545!!##77##data44!!";

如何删除##664545##数据!!从字符串

编辑:如果我们知道字符串中的起始值,即,##66## 和结束值,即,!!

在主字符串中如何删除从起始模式开始的字符,起始模式之后直到结束模式的数据

      My expected output will be ##55##data1!##77##data44!!
   var a="##55##data1!!##66##data4545!!##77##data44!!";

how to remove ##664545##data!! from the string

Edit:if we know the start value in a string i.e,##66## and the end value ie,!!

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!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傾城如夢未必闌珊 2024-10-01 18:03:17

使用 javascript 和 regex -

a.replace(/##66##[a-zA-Z0-9]*!!/g,"") 

如果您想对此进行参数化,那么您可以按照下面给出的方式执行操作,其中 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,"");

Using javascript and 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-

    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,"");
失与倦" 2024-10-01 18:03:17

正则表达式方式,使用全局标志 g 来捕获所有匹配项:

a.replace(/##66##data!!/g,"")

Regex way, with global flag g to catch all matches:

a.replace(/##66##data!!/g,"")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文