Practical examples

Since the matching of regex is a dynamic process, we need to provide slideshow mode examples. These are best viewed with a recent browser. You should use navigation buttons for exploring each examples.

In these example we don't use any particular language syntax for regex or input text. We will use \n and the like for special character in input text but we will not escape in quotes or even slashes.

Special symbols are used to mark position:

  • Saved options for backtracking will be shown over the text and under the regex using  symbols.
  • Match tries will be shown under the text using ^ symbols.
  • Successful match will be shown under the text using ¯ symbols.
  • Part of the regex currently driving the process will be shown over the regex using _ symbols.

Introductory example


Initial state



    Step 1 of 9

  • In this example, we will separate absolute or relative path and a filename.
  • No explicit validation is made on names for the purpose of this example.

This first example is really simple, but it already shows how complex and inefficient could be backtracking in regular expressions. More illustrations of an NFA engines is available:

  • Backtracking in regards to correctness and efficiency
    • <.+>: an easy crafted but imprecise regex
    • <.+?>: Still imprecise but not as lazy as we could thought
    • <(?:/[^<>]|[^/<>])+/>: More precise but still inefficient
    • <(?:[^/<>]+|/[^<>])+/>: Still more precise and nearly efficient
    • <[^/<>]+(?:/+[^/<>]+)*/>: The unrolling the loop technique