Live data from Hacker News

Regular Expressions in CoffeeScript are Awesome

elijahmanor.com

21–28 of 28 posts

Re: Regular Expressions in CoffeeScript are Awesome

#21
That has nothing to do CoffeeScript, most regex parser implementation support this via a flag. I've seen it done in PHP, Ruby, Perl, Objective-C. For languages whose regular expression engine don't support this, it's easy enough to achieve it via string concatenation.

Re: Regular Expressions in CoffeeScript are Awesome

#22
post #21

That has nothing to do CoffeeScript, most regex parser implementation support this via a flag. I've seen it done in PHP, Ruby, Perl, Objective-C. For languages whose regular expression engine don't support this, it's easy enough to achieve it via string concatenation.

Python has it, too.

Re: Regular Expressions in CoffeeScript are Awesome

#24
post #6

In JS you can comment regular expressions, too... :) var foo = new RegExp( '\\d\+' + // First digit '-' + // Delimiter '\\d\+' // Second digit ); foo.test("1234-5432");

True, but then you have the overhead of string concatenation... although in the large scheme of things that is probably very small, unless you are doing it in a huge loop, but then you'd cache that RegExp anyway.

Concatenation of string literals can be compiled away.

Re: Regular Expressions in CoffeeScript are Awesome

#26
post #23

is there any performance penalty?

I'm pretty sure that these expressions are simplified to normal JavaScript expressions at compile time, so there is no performance penalty.

Even if they were compiled at runtime, the performance penalty would probably be negligible unless you were randomly compiling the expression in the middle of an inner loop or something equally silly.

Re: Regular Expressions in CoffeeScript are Awesome

#27

You 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...

You shouldn't try to validate an email address by any means other than sending mail to it. If it works, it's valid.

Re: Regular Expressions in CoffeeScript are Awesome

#28

"Let's face it, regular expressions aren't for everyone." Wait, since when aren't they? I would have thought basic regex skills were a baseline shibboleth of a programmer. I even know several non-technical people that are proficient.

Your comment reminded me of Jamie Zawinski's tongue-in-cheek quotation "Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems." (http://regex.info/blog/2006-09-15/247)

Jestful, off-the-wall comments aside, I love regex. It takes away a great deal of the drudgery associated with processing volumes and volumes of text. I can't imagine not having it.

(Aside: Now that you mention it, I can think of a couple people who aren't programmers who use regex pretty frequently because it makes their life a little easier even if it isn't highly advanced, super-dense regex.)

Post reply on HN