Clojure seems to have some nice ideas
Last active
August 29, 2015 13:56
-
-
Save shedd/9077067 to your computer and use it in GitHub Desktop.
A CoffeeScript for RegExps?
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
# Sample RegEx with CoffeeScript comments | |
# from http://www.elijahmanor.com/regular-expressions-in-coffeescript-are-awesome/ | |
emailPattern = /// ^ # begin of line | |
([\w.-]+) # one or more letters, numbers, _ . or - | |
@ # followed by an @ sign | |
([\w.-]+) # then one or more letters, numbers, _ . or - | |
\. # followed by a period | |
([a-zA-Z.]{2,6}) # followed by 2 to 6 letters or periods | |
$ ///i # end of line and ignore case |
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
# The example translated | |
emailPattern = Pattern( line_start(). | |
match([:letters, :numbers, '_', '.', '-'], options => {limit: '1+'}). | |
match('@'). | |
match([:letters, :numbers, '_', '.', '-'], options => {limit: '1+'}). | |
match('.'). | |
match([:letters, '.'], options => {limit: '2-6'}). | |
line_end(). | |
case_insensitive() | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One more: https://github.com/jimweirich/re
Personally I haven't bothered with anything like that before, regexps aren't used that often... Usually there's just one or two in an app that are longer than several characters and they're usually email/username validations that you write once and never change again.