How do i find the numbers that is not followed by a word character with regex?

Tags: ,



I’m trying to do this thing that searches the number that is not followed by an “i”, for example:

21i and 16, it should only match 16

I tried /d+(?!i)/ but it also matches the 2 in 21i, how do i fix it?

Answer

So basically you need to find a cascade of numbers that not followed by an i nor another number:

/d+(?![id])/

You may see the test cases here



Source: stackoverflow