How to remove double underscore using JavaScript

This question already has an answer here:

  • How to replace all occurrences of a string in JavaScript? 41 answers

  • 你可以使用replace()和正则表达式匹配连续的下划线:

    'stack__overflow___website'.replace(/_+/g, '_')
    

    var myString = "stack__overflow___website",
        myFormattedString = myString.split('__').join('_');
    
    链接地址: http://www.djcxy.com/p/16840.html

    上一篇: javascript:string.replace不起作用

    下一篇: 如何使用JavaScript删除双下划线