0

I am struggling to get the regular expression working correctly.

Basically, I have the string looks like below feeding to a function to get the value in the last parenthesis

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

This function only get the value in the first parenthesis. Please help with the Reg pattern of how to get the value in the last parenthesis of the string.

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);
    }   
}
Milacay
  • 1,407
  • 7
  • 32
  • 56

0 Answers0