user3634329 user3634329 - 15 days ago 3x
C Question

What would the regex be

Here's my question I was given: Write a regular expression to recognize strings with that have any number of a's, b's and c's in the order of abc. However, any number of d's may be among the a's, b's and c's.

Positive Examples:



Negative examples:

dabcddadbdd because 2nd sequence starts but does not finish.

ddcdd because c without leading ab

ddaddbddcaddbcdd because 2 abc sequences

Here's what I've tried:



If I understood your question well, the idea is that a must be before b and b before c if any of them are present. Additionally there might be some d in whatever place.

If that's the case then you can use a regex like this:


Working demo