Matching parts of a string that do not contain consecutive dashes

I need a regular expression that will match strings of letters that don't contain two consecutive dashes.

I came close to this regex that uses lookaround (I don't see an alternative):

([-a-z](?<!--))+

Why the following is indicated:

qsdsdqf - sqdfqsdfazer - azerzaer-azerzear

Produces three matches:

qsdsdqf-
sqdfqsdfazer-
azerzaer-azerzear

However, I want to:

qsdsdqf-
-sqdfqsdfazer-
-azerzaer-azerzear

So my regex is losing the first dash, which I don't want.

Who can give me a hint or regex that can do this?

+3
source share
2 answers

:

-?([^-]-?)*

, .

+5

, , , , . ? , :

(?<=-)(?=-)

, , , :

(?:[^-]+|-(?<!--)|\G-)+

-(?<!--) , , . \G- , ; , ( ), - , .

, , ; Java, \G lookbehinds.

0

Source: https://habr.com/ru/post/1758815/


All Articles