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
r"
(?<!\S)(?:-\w+(?:-\w+)*|\w+(?:-\w+)*-)(?!\S)
"
gm
Input 1
1
New
here are some word sub-words -word1 word2- sub-word2 word3- -word4 -word5 example word6- word7- another one -word8 -word9 a-b-c- -some- sugar-free sugar-free- -sugar-free
Substitution
here are some word sub-words -word1 word2- sub-word2 word3- -word4 -word5 example word6- word7- another one -word8 -word9 a-b-c- -some- sugar-free sugar-free- -sugar-free