JavaScript/regex: Remove text between parentheses

前端 未结 5 1598
陌清茗
陌清茗 2020-11-29 00:41

Would it be possible to change

Hello, this is Mike (example)

to

Hello, this is Mike

using JavaScript with

5条回答
  •  再見小時候
    2020-11-29 01:14

    var str = "Hello, this is Mike (example)";
    
    alert(str.replace(/\s*\(.*?\)\s*/g, ''));
    

    That'll also replace excess whitespace before and after the parentheses.

提交回复
热议问题