Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
/
((?<!\p{L})(?=\d(?=(?:[- _]*\d){3,4}(?!\p{L})))|(?!^)\G)[- _]?\d(?!\d*\p{L})
/
g
Input 1
1
New
"0000" will become "****" "any text 000 00 more texts" will become "any text ***** more texts"..notice that the space is removed "any text 000 00 more texts 00" will become "any text ***** more texts 00" "any text 000 00 more texts 00 00" will become "any text ***** more texts ****" "any text 00-00 more texts 00_00" will become "any text **** more texts ****"
Extraction
"0000" will become "****" "any text 000 00 more texts" will become "any text ***** more texts"..notice that the space is removed "any text 000 00 more texts 00" will become "any text ***** more texts 00" "any text 000 00 more texts 00 00" will become "any text ***** more texts ****" "any text 00-00 more texts 00_00" will become "any text **** more texts ****"