Trying to get “Table 2” or whatever table number it might be (sometimes 2 digits) into a variable. Any idea why this is returning null?
var productText = '25-08-12 Boat Cruise (Table 2)';
var rgx = /^\(\)$/;
var newText = productText.match(rgx);
alert(newText);
Use the following instead:
When you have
/^\(\)$/, you are actually trying to match the string"()", no more, no less. Instead, you should match, anywhere in the text, a(, store everything between it and the next)in a capturing group([^)]+), so that you can refer to the captured group later on withmatch[1].If you want just the number, use
/\(Table (\d+)\)/.