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
/
\b(long|anyword)\b\K[- ](?=(?:(?1))\b)
/
gm
Input 1
New
Sample text: test text long long test text test text long long long long long long test text test text long long test test long long long test text How it should be: test text long-long test text test text long-long-long-long-long-long test text test text long-long test test long-long-long test text How does it work now: test text long-long test text test text long-long long-long long-long test text test text long-long test test long-long long test text
Extraction
Sample text: test text long long test text test text long long long long long long test text test text long long test test long long long test text How it should be: test text long-long test text test text long-long-long-long-long-long test text test text long-long test test long-long-long test text How does it work now: test text long-long test text test text long-long long-long long-long test text test text long-long test test long-long long test text