Regex que no contiene la subcadena 010
Frecuentes
Visto 3,949 veces
3 Respuestas
1
If you want to match binary string (strings which contain only 1
y 0
's) but exclude strings which contain the string 010
, perhaps use something like this:
^((?!010)[01])*$
This will match any sequence of zero or more 0
or 1
characters such that the sequence does not contain the substring 010
. The start (^
) y punto ($
) anchors will ensure that no additional characters are allowed in the input string.
respondido 27 nov., 13:04
This requires Perl-compatible regex, while it looks like the OP is looking for a pure BRE. - triples
0
Your attempt requires any stretch of zeros to be followed by 10 which is clearly a violation of your constraint. Instead, require any 1 to be followed by at least one more, or end of string.
(0*(1(1+|$))*)*
respondido 27 nov., 13:05
0
Use an anchored negative look ahead:
^(?!.*010)[01]+$
respondido 27 nov., 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas regex binary or haz tu propia pregunta.
In practice, I would recommend two regular expressions if possible:
!/010/ && /whateverelse/
- user2864740If this is for an automata class, then expand the aceptado formas. - user2864740