Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post2.news.xs4all.nl!newszilla.xs4all.nl!not-for-mail From: Eric Bednarz Newsgroups: comp.lang.javascript Subject: Re: ScreenName validation Organization: Eric Conspiracy Secret Labs References: <53ccd13b-a933-4bbc-ba0a-7061cc9064cd@4g2000yqv.googlegroups.com> Reply-To: ebednarz@gmx.net X-Eric-Conspiracy: There is no conspiracy Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Date: Sat, 12 Jan 2013 02:31:56 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3.50 (darwin) Cancel-Lock: sha1:5oIt+W0mBcBDlj2XlUh4dOW2exc= MIME-Version: 1.0 Lines: 59 NNTP-Posting-Host: 83.163.169.80 X-Trace: 1357954315 dreader35.news.xs4all.nl 6339 83.163.169.80:52981 Xref: csiph.com comp.lang.javascript:18084 Scott Sauyet writes: [redundant regexp character class escape sequences] > Although this is true, you also have to be careful about the placement > of hyphens, and carets. You have to be careful about anything anyway because regular expressions are hard to grok. Because: * they are difficult to read anyway (especially long ones in implementations without a /x matching mode) * implementation differences can make your head spin, especially if you don't use a particular language (version[1]) exclusively * it's very easy to make grave conceptual mistakes even for what appears to be a trivial task (e.g. match an attribute specification within an HTML start tag), with resulting problems ranging from false positives to potential performance nightmares (depending on all those unforeseen subjects, of course) [1] take ECMAScript 3 vs 5: are regexp literals cached or not, and why (not)? > And as Stefan pointed out, JSLint takes > exception to certain unescaped characters in character classes > (possibly only the hyphen.) I'm all for catering (semi-)popular tools as long as it doesn't hurt your brain, e.g. (function () {} ()) vs (function () {})(), who cares, but I'm also all against writing silly code to satisfy challenged code analysis (be it JSLint, one's pet-IDE or whatnot). I know I've done that a lot, and it's not going anywhere, really fast. The only answer to that is convincing bug tracker reports, or emigration. > While this is equivalent: > > /^[a-z._-]{2,12}$/ > > I would still prefer this: > > /^[a-z._\-]{2,12}$/ > > especially as it doesn't fall apart if you switch the position of the > last two character identifiers: > > /^[a-z.\-_]{2,12}$/ As much as I like things to be portable, I don't really buy that, because it still falls apart if you only move one character around; if you are smart enough to know that you need to move the escape sequence as a whole, why wouldn't you just leave the unescaped hyphen/minus at the end of the character class, as the average style guide (your locale may vary) suggests?. > But really it was just a brain fart. I use regexes when I need them, > but am generally in the "two problems" camp. That's a rather biased source, don't you think? Using (and remembering) elisp regexp syntax in the (X)Emacs echo area is a lot like meeting Kurtz at the end of the Congo River.