Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
@"
^\d{5}(?:-\d{4})?(?!\S)|(?<!\S)\d{5}(?:-\d{4})?(?=[\r\n]|$)
"
gm
Input 1
1
New
Nothing to match in the middle 06000 or 06000-0000 on this line 06111 these are ok 06222-1111 06333-1111 and these 06444 06555-333 these are not 06666-444 06777-66666 also not 06888-77777 06888-00001 but this last one is 06999-9999 Some additional cases here: 12345abc something non-whitespace after it? no abc12345 something non-whitespace before it? no Just on its own? yes 12345
Substitution