Skip to content
Advertisement

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

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?

Advertisement

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

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement