I know this is possible but I can't find the answer with the Google keywords I'm using, so I'm asking this in the hope it helps someone else too.
I'd like to regex match a substring but only return part of that substring.
Here's my attempt:
const t = "The 2 items contained 150 calories";
t.match(/(\d+) calorie/g).replace(" calorie", "");
This returns 150 calorie
but what I want is just 150
.
I can hack it with t.match(/(\d+) calorie/g)[0].replace(" calorie", "")
but perhaps there's a way to do it just with regexes?