用于在最后一个括号()之间获取文本的正则表达式 [英] Regex for getting text between the last brackets ()
本文介绍了用于在最后一个括号()之间获取文本的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用javascript提取最后()
之间的文字
I want to extract the text between the last ()
using javascript
例如
var someText="don't extract(value_a) but extract(value_b)";
alert(someText.match(regex));
结果应为
value_b
感谢您的帮助
推荐答案
试试这个
\(([^)]*)\)[^(]*$
看到它 regexr
var someText="don't extract(value_a) but extract(value_b)";
alert(someText.match(/\(([^)]*)\)[^(]*$/)[1]);
括号内的部分存储在捕获组1中,因此您需要使用 match()[1]
来访问结果。
The part inside the brackets is stored in capture group 1, therefor you need to use match()[1]
to access the result.
这篇关于用于在最后一个括号()之间获取文本的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文