2013-03-06 110 views
1

我正在寻找一个JavaScript正则表达式,允许我删除括号中的任何文本并包含括号本身。括号内的正则表达式和字符串

例子:

"hello world (some Text and Number here)" 

我要修剪(some Text and Number here)并得到结果为:

"hello world" 
+0

你会得到嵌套的括号吗? – 2013-03-06 06:14:55

+0

不是真的,但它也很好地知道它的正则表达式。 – 2013-03-06 06:20:32

回答

2

你有没有试过这一个:

\(.*?\) 

实际JS可能会像dis:

var a = "hello world (someText and Number here)"; 
a = a.replace(/\(.*?\)/, ""); 
+0

也添加全局标志。 – dfsq 2013-03-06 06:08:02

+0

确保一遍又一遍地应用它,直到它不更改字符串,如果嵌套括号可能会出现 – Patashu 2013-03-06 06:08:34

相关问题