Regular Expressions in CoffeeScript are Awesome
elijahmanor.com
Regular Expressions in CoffeeScript are Awesome
1–10 of 28 posts
Re: Regular Expressions in CoffeeScript are Awesome
#2For those using plain JavaScript -- or wanting to do a one-off conversion -- I wrote a simple JS function that converts an extended RegEx to a plain one:
http://blog.mackerron.com/2010/08/08/extended-multi-line-js-...
Re: Regular Expressions in CoffeeScript are Awesome
#3http://docs.python.org/library/re.html#re.VERBOSE
a = re.compile(r"""\d + # the integral part
\. # the decimal point
\d * # some fractional digits""", re.X)
b = re.compile(r"\d+\.\d*")Re: Regular Expressions in CoffeeScript are Awesome
#4"()[]:;@,\\\"!#$%&'*+-/=?^_`{}| ~ ? ^_`{}|~."@example.org
is a perfectly valid email address [1]
[1] http://en.wikipedia.org/wiki/Email_address#Valid_email_addre...
Re: Regular Expressions in CoffeeScript are Awesome
#5You shouldn't validate emails by regular expressions since, technically (at least according to spec) "() []:;@,\\\"!#$%&'*+-/=?^_`{}| ~ ? ^_`{}|~."@example.org is a perfectly valid email address [1] [1] http://en.wikipedia.org/wiki/Email_address#Valid_email_addre...
AFAIK there are regular expressions that cover all valid email addresses (and some invalid, but better than not recognizing one that is valid).
Although it gets pretty nasty: http://www.diablotin.com/librairie/autres/mre/chBB.html
Re: Regular Expressions in CoffeeScript are Awesome
#6 var foo = new RegExp(
'\\d\+' + // First digit
'-' + // Delimiter
'\\d\+' // Second digit
);
foo.test("1234-5432");Re: Regular Expressions in CoffeeScript are Awesome
#7In JS you can comment regular expressions, too... :) var foo = new RegExp( '\\d\+' + // First digit '-' + // Delimiter '\\d\+' // Second digit ); foo.test("1234-5432");
Re: Regular Expressions in CoffeeScript are Awesome
#8You shouldn't validate emails by regular expressions since, technically (at least according to spec) "() []:;@,\\\"!#$%&'*+-/=?^_`{}| ~ ? ^_`{}|~."@example.org is a perfectly valid email address [1] [1] http://en.wikipedia.org/wiki/Email_address#Valid_email_addre...
More like you shouldn't validate emails by using crappy regular expressions? AFAIK there are regular expressions that cover all valid email addresses (and some invalid, but better than not recognizing one that is valid). Although it gets pretty nasty: http://www.diablotin.com/librairie/autres/mre/chBB.html
Re: Regular Expressions in CoffeeScript are Awesome
#9Python, too: http://docs.python.org/library/re.html#re.VERBOSE a = re.compile(r"""\d + # the integral part \. # the decimal point \d * # some fractional digits""", re.X) b = re.compile(r"\d+\.\d*")
Re: Regular Expressions in CoffeeScript are Awesome
#10Python, too: http://docs.python.org/library/re.html#re.VERBOSE a = re.compile(r"""\d + # the integral part \. # the decimal point \d * # some fractional digits""", re.X) b = re.compile(r"\d+\.\d*")
Ohh nice, maybe there is where CoffeeScript got inspiration from? The syntax looks very similar.
PCRE isn't as good as Perl's regexps, but not bad. (I've helped people with PCRE problems that worked in Perl.)
Edit: I googled myself. :-) The Python lib isn't pcre (anymore), it is something home rolled. The answer to the parent question about inspiration is: Most everyone has copied the Perl syntax (except, irritatingly, Emacs).
Edit 2: herge -- Perl is ~ a superset of awk. Use that. (Check -n and -e flags in perldoc perlrun.)