Regex que no contiene la subcadena 010

I'm trying to write a regex expression to exclude binary strings that contain 010.
I'm not quite sure what to write.

I have this to start with but I'm not too sure what to do:



preguntado el 27 de noviembre de 13 a las 04:11

In practice, I would recommend two regular expressions if possible: !/010/ && /whateverelse/ -

If this is for an automata class, then expand the aceptado formas. -

3 Respuestas

If you want to match binary string (strings which contain only 1y 0's) but exclude strings which contain the string 010, perhaps use something like this:


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

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.


respondido 27 nov., 13:05

Use an anchored negative look ahead:


respondido 27 nov., 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.