Created
March 19, 2015 22:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first one should be
/a+/ == /aa*/
, not/a+/ == /a|a*/
.