I am trying to match when there is a value with parenthesise.
var onsuccess = "aaa;bbb(ccc)";
onsuccess.split(';').forEach(function (success) {
var re = new RegExp("\(.*?\)");
document.write(success + ": " + success.match(re) + "<br>");
});
Output is
aaa: ,
bbb(ccc): ,
Expected is
aaa: false
bbb(ccc): true
Where am I going wrong? I have been using this page as an example:
http://www.regular-expressions.info/javascriptexample.html
Here is my fiddle: http://jsfiddle.net/valamas/8B5zw/
thanks
The working demo.
Note: if you using
new RegExp(...), you need to escape your backslash.You regex should be
var re = new RegExp("\\(.*?\\)");, but since there is no variable in your regex, you should just use the regex literal instead.