Does lookaround affect which languages can be matched by regular expressions?

The answer to the question you ask, which is whether a larger class of languages than the regular languages can be recognised with regular expressions augmented by lookaround, is no. A proof is relatively straightforward, but an algorithm to translate a regular expression containing lookarounds into one without is messy. First: note that you can … Read more

Regex to match all permutations of {1,2,3,4} without repetition

You can use this (see on rubular.com): ^(?=[1-4]{4}$)(?!.*(.).*\1).*$ The first assertion ensures that it’s ^[1-4]{4}$, the second assertion is a negative lookahead that ensures that you can’t match .*(.).*\1, i.e. a repeated character. The first assertion is “cheaper”, so you want to do that first. References regular-expressions.info/Lookarounds and Backreferences Related questions How does the regular … Read more

Regular Expressions: Is there an AND operator?

Use a non-consuming regular expression. The typical (i.e. Perl/Java) notation is: (?=expr) This means “match expr but after that continue matching at the original match-point.” You can do as many of these as you want, and this will be an “and.” Example: (?=match this expression)(?=match this too)(?=oh, and this) You can even add capture groups … Read more