I would like to extract the text within () brackets. The string looks like this: It is within the
Some text: 5 (some numbers) + some more numbers
asdfkjhsd: 7 (6578) + 57842
djksbcuejk: 4 (421) + 354
My javascript looks like this:
var fspno = document.getElementsByTagName("td")[142].innerText;
var allfsp = fspno.match();
I want this script to collect all numbers within the brackets in an array. I used
fspno.match(/\((.*?)\)/g);
but it returned with the brackets. I want only the text inside the brackets.
Any help would be appreciated. Thanks.
There’s no way in javascript to extract all matches with all groups at once, therefore you either have to use
execin a loop:or abuse
String.replaceto collect the matches:In your particular case, however, it’s possible to rewrite the expression so that it doesn’t contain groups and can be used with
String.match: