Many computer languages have complex regular expressions tools. For example, in Javascript you have global flags, escape characters, whitespace character, assertions, character classes, groups and ranges etc. I'm wondering if using just the 3 basic regular expressions operators as defined in formal languages, that is concatenation, alternation and Kleene star can achieve the same result as any pattern described with more tools as for example in Javascript. Is there a theorem about this?

  • 1
    $\begingroup$ Alternation? Why didn't the book or doc you're reading call it disjunction? $\endgroup$ Commented Sep 25, 2020 at 17:01
  • 4
    $\begingroup$ The features that you list include things that aren't part of the regular expression ("global flags"), are mere syntactic representation ("escape characters"), or are shorthands for alternation ("character classes", "range"). You already have an answer for your question as written, but if you're interested in this subject, you might want to spend some time understanding regular expressions better. $\endgroup$
    – ruakh
    Commented Sep 25, 2020 at 21:27
  • 5
    $\begingroup$ @JohnnyApplesauce -- "alternation" is often used in describing regular expressions. I suspect it's more common than "disjunction", but both mean the same thing. $\endgroup$ Commented Sep 26, 2020 at 15:31

2 Answers 2


Regular expressions using only concatenation, alternation and Kleene star describe regular languages. In contrast, extended regular expressions available in modern programming languages can describe non-regular languages. For example, (.*)\1 describes the language $\{ ww : w \in \Sigma^* \}$, which is not even context-free.

  • 1
    $\begingroup$ What about extended regexes that don’t have back references? Or without look aheads or look behinds? Such as Thompson NFA approaches like Go. $\endgroup$ Commented Sep 25, 2020 at 17:03
  • 22
    $\begingroup$ If you change the question, you might get a different answer. The exact answer depends on the exact question. $\endgroup$ Commented Sep 25, 2020 at 17:04

Most real-world regular expression constructs can be converted to what I lovingly call ivory tower regular expressions.

For example:

  • $a? = (\epsilon + a)$
  • $a+ = a(a*)$
  • $a\{n,m\} = aaa\ldots{}a(a?)(a?)\ldots{}(a?)$ where $a$ is repeated $n$ times and $(a?)$ is repeated $m$ times.

Most lookahead operations can be expressed as the intersection of two languages (perhaps you need some clever product constructions, starting from the state you are currently at, or some such tricks and techniques).

Back-references make the whole exercise NP-complete, though; see e.g. https://perl.plover.com/NPC/NPC-3COL.html.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.