Computer science has automata theory with lessons on regular expressions and FSM. How are these different from regex engines used in programming such as C++, Perl, PHP etc.?

I would like to know some differences i.e. stuff that can only be done with regexps in programming but cannot be done in formal regexps in computer science.

I heard there are a lot are differences but what are some major ones? Let's take Perl Compatible Regular Expressions (PCRE) or Boost.Regex for comparsion.


marked as duplicate by Apass.Jack, Evil, xskxzr, David Richerby, Yuval Filmus formal-languages Jan 13 at 11:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ I can elaborate my answer further, but most major differences boil down to a simple fact that in theoretical CS regular expressions aren't designed to find and/or replace substrings in a longer string. They are used to check "whole matches", i.e., whether a given string belongs to a given language. This makes the whole topic of lazy matching, groups or backreferences irrelevant. Lazy/eager matching is especially important here, since they require different types of automata. $\endgroup$ – rg_software Jan 12 at 14:19
  • $\begingroup$ @rg_software: Sure, you can post the differences as a list in answer. Thanks. $\endgroup$ – cpx Jan 12 at 14:32
  • $\begingroup$ @rg_software, I recommend that you write an answer about finding or replacing substrings as well as lazy and eager matching to that question. $\endgroup$ – Apass.Jack Jan 12 at 17:29