JavaScript/regex: Remove text between parentheses

前端 未结 5 1603
陌清茗
陌清茗 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:02

    I found this version most suitable for all cases. It doesn't remove all whitespaces.

    For example "a (test) b" -> "a b"

    "Hello, this is Mike (example)".replace(/ *\([^)]*\) */g, " ").trim(); "Hello, this is (example) Mike ".replace(/ *\([^)]*\) */g, " ").trim();

提交回复
热议问题