Skip to content

Instantly share code, notes, and snippets.

@tom-lord
Created March 19, 2015 22:33
Show Gist options
  • Save tom-lord/7280ff29d038b31bb7ac to your computer and use it in GitHub Desktop.
Save tom-lord/7280ff29d038b31bb7ac to your computer and use it in GitHub Desktop.
A few examples of how regular expressions can all be decomposed into the same 4 symbols
/a+/ == /a|a*/
/a?/ == /ε|a/
/a{2,4}/ == /aa|aaa|aaaa/
/a{3,} == /aaaa*/
/[a-d]*/ == /(a|b|c|d)*/
/\d\n?/ == /(0|1|2|3|4|5|6|7|8|9)(ε|\n)
# Note: My use of the == operator here is not to be taken too literally...
# In ruby, Regexp equality is not based purely on what strings they match!
# http://ruby-doc.org/core-2.2.1/Regexp.html#method-i-3D-3D
@bfontaine
Copy link

The first one should be /a+/ == /aa*/, not /a+/ == /a|a*/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment