What is the complexity of regular expression?

Ahmad Farid picture Ahmad Farid · Dec 7, 2010 · Viewed 34.3k times · Source

What is the complexity with respect to the string length that takes to perform a regular expression comparison on a string?

Answer

NPE picture NPE · Dec 7, 2010

The answer depends on what exactly you mean by "regular expressions." Classic regexes can be compiled into Deterministic Finite Automata that can match a string of length N in O(N) time. Certain extensions to the regex language change that for the worse.

You may find the following document of interest: Regular Expression Matching Can Be Simple And Fast.