【问题标题】:How to remove numbers between brackets and a slash between them in jquery如何在jquery中删除括号之间的数字和它们之间的斜线
【发布时间】:2015-01-13 10:27:13
【问题描述】:

我有一长串字符串如下

Corporate Docs (Only papers) - Paris (45/9833)

我希望字符串为

Corporate Docs (Only papers) - Paris

(不包括括号、反斜杠和数字)

我尝试先删除数字,然后像这样删除剩余部分

childItem.replace(/\d+/g, '');
childItem.replace('(/)', '');

但没有运气。任何帮助深表感谢。谢谢。

【问题讨论】:

    标签: jquery replace numbers character


    【解决方案1】:

    只需使用正则表达式

    /\([\s\d\/]+\)/
    

    并用空字符串替换

    var str = "Corporate Docs (Only papers) - Paris (45/9833)";
    console.log(str.replace(/\([\s\d\/]+\)/, "")
                   .trim()); // trim to remove the last space if any
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-21
      • 1970-01-01
      • 2017-12-03
      • 2018-03-05
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多