2013-03-06 107 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

相關問題