If lookbehind and lookahead are available, then the following should work:
(?<!\d)(\d{1,3}|\d{5,})(?!\d)
Explanation:
(?<!\d)
If you cannot use search terms, follow these steps:
\b(\d{1,3}|\d{5,})\b
Explanation:
\b
Python example:
>>> regex = re.compile(r'(?<!\d)(\d{1,3}|\d{5,})(?!\d)') >>> regex.findall('1 22 333 4444 55555 1234 56789') ['1', '22', '333', '55555', '56789']
Andrew Clark
source share