I am trying to alert the numbers that fall within the parenthesis:
var str2 = "This is a string (3444343) with numbers.";
var patt2 = \((.*?)\);
alert(str2.match(patt2));
jsfiddle: http://jsfiddle.net/BinaryAcid/8nx9v/1/
Based on your original question, this would do:
var str2 = "This is a string (3444343) with numbers.";
var patt2 = /\((.*?)\)/;
alert(str2.match(patt2)[1]);
An updated jsFiddle example: http://jsfiddle.net/S99jd/
For your input string, it alerts 3444343 (without parenthesis).
Your snippet needed:
/ to create the regex,1, as match() returns an array of elements, where element at index0 is the full match and following indexes correspond to the matching groups).For a lot more information and help on using regular expressions in JavaScript / ECMAScript, visit: http://www.regular-expressions.info/javascript.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With