jquery在最后一个实例括号中获取值

时间:2017-04-04 21:31:26

标签: javascript jquery regex

我正在努力让正则表达式正常工作。

基本上,我有一个字符串看起来像下面的函数,以获取最后一个括号中的值

This is a test (ABC) and (500%)

此函数仅获取第一个括号中的值。请帮助使用Reg模式,了解如何在字符串的最后一个括号中获取值。

function getRate(str, hiddenElement)
{
    //alert(str);
    $("#" + hiddenElement).val('');
    var regExp = /\(([^)]+)\)/;
    var matches = regExp.exec(str);
    var matchedStr = (matches[1]);  
    //alert(matchedStr)
    if (matchedStr != "")
    {
        matchedStr = matchedStr.replace("%", "");
        alert("Matched: " + matchedStr);
        $("#" + hiddenElement).val(matchedStr);
    }   
}

0 个答案:

没有答案