Regex to extract ALL numbers excluding numbers with letters like 1st, 2nd etc. in JavaScript?

Viewed 16

The following regex pattern \d+ works fine for most of my use cases when I do a match to extract all possible digits from a string:

let extractedNums = string.match(/\d+/g);

However, it also matches a number that is immediately followed by a non-digit character, where I instead want to ignore it for example; "he came in 2nd place".

The regex should NOT extract the "2nd" in the above string aswell as a digit as it also contains letters "nd".

0 Answers
Related