zoukankan      html  css  js  c++  java
  • 替换掉一段 以 $ 开头 $ 结尾 的字符串

    可以看到,^ 代表从字符串开头进行匹配,$ 代表从字符串末尾进行匹配

    ^ 和 $ 不能一起用,用了其中任何一个,g 就不起作用了。

    没有 g 找到一个就不会再找了,有 g 会一直找完整个字符串。

    const str = "&一&二&三&四&五&"
    
    str.replace(/^[&]+[u4e00-u9fa5]+[&]/,"")
    // "二&三&四&五&"
    str.replace(/[&]+[u4e00-u9fa5]+[&]$/,"")
    // "&一&二&三&四"
    str.replace(/([&]+[u4e00-u9fa5]+[&])/,"")
    // "二&三&四&五&"
    str.replace(/[&]+[u4e00-u9fa5]+[&]/g,"")
    // "二四"
  • 相关阅读:
    poj 2000
    poj1316
    poj1922
    poj2017
    poj1833 排列
    poj1338
    poj2136
    poj2242
    IE兼容html5标签
    绑定事件后,某些情况下需要解绑该事件
  • 原文地址:https://www.cnblogs.com/MrZhujl/p/13504150.html
Copyright © 2011-2022 走看看