I got a HTML Table with values inside each row.
The datas inside the consist the following format:
ABCD (1000.50)
$('.tdclass').each(function(index){
var test = push($(this).text().match(?regex?));
});
Well, regex is definitely not one of my strength ;-)
What is the according regex to get the values inside the parentheses?
Any help would be appreciated!
If the first part of a string is a fixed length, you can avoid complicated procedures entirely using slice()
:
var str = "ABCD (1000.50)";
alert(str.slice(6, -1));
//-> "1000.50"
Otherwise, you can use indexOf()
and, if you need it, lastIndexOf()
to get the value:
var str = "ABCDEFGHIJKLMNO (1000.50)",
pos = str.indexOf("(") + 1;
alert(str.slice(pos, -1));
//-> "1000.50"
alert(str.slice(pos, str.lastIndexOf(")");
//-> "1000.50"
A minimal regex of \((.*)\)
would do the trick, however this doesn't account for multiple brackets, and there's no need to include 4 characters prior to that. It literally says 'match (, followed by as many non-new-line characters as possible, followed by )'
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