Skip to content

Instantly share code, notes, and snippets.

@shedd
Last active August 29, 2015 13:56
Show Gist options
  • Save shedd/9077067 to your computer and use it in GitHub Desktop.
Save shedd/9077067 to your computer and use it in GitHub Desktop.
A CoffeeScript for RegExps?
# 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
# 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()
)
@mackuba
Copy link

mackuba commented Mar 5, 2014

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.

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