eran otzap
eran otzap

Reputation: 12533

Regex Match 2 Digits 0 to 9

i'm new to regex i'm trying to match a case where there are 2 digits both can be from 0-9

something along the lines of

[0-9][0-9] 

for example :

11 10 01

Upvotes: 3

Views: 15814

Answers (3)

daftcoder
daftcoder

Reputation: 435

Including the @Kobi's suggestion.

(?<![0-9])[0-9]{2}(?![0-9])

Upvotes: 3

everag
everag

Reputation: 7662

I believe ^\d{2}(\s\d{2})+$ should fit your needs.

Test this Regex at Regex101

PS: Learn, try for your own and come to us without just the problem but with some efforts next time. :)

Upvotes: 5

stema
stema

Reputation: 92986

What you need are word boundaries, try

\b\d{2}\b

See it here on Regexr.

\b matches a wordboundary (in a lot of languages), thats the change from a wordcharacter to a non wordcharacter. Means, the regex would match 2 digits, if there is no digit or letter before and ahead.

\d works in most regex flavours as a shortcut for [0-9], some does not support this shortcut and some use the Unicode version and match any kind of number with \d

Upvotes: 5

Related Questions