Regex with all optional parts but at least one required

Posted by Alan Mendelevich on Stack Overflow See other posts from Stack Overflow or by Alan Mendelevich
Published on 2010-05-10T14:09:03Z Indexed on 2010/05/10 14:14 UTC
Read the original article Hit count: 351

Filed under:
|

I need to write a regex that matches strings like "abc", "ab", "ac", "bc", "a", "b", "c". Order is important and it shouldn't match multiple appearances of the same part.

a?b?c? almost does the trick. Except it matches empty strings too. Is there any way to prevent it from matching empty strings or maybe a different way to write a regex for the task.

© Stack Overflow or respective owner

Related posts about regex

Related posts about .NET