Reputation: 12533
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
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
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