Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #18084
| From | Eric Bednarz <bednarz@fahr-zur-hoelle.org> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: ScreenName validation |
| Organization | Eric Conspiracy Secret Labs |
| References | (1 earlier) <53ccd13b-a933-4bbc-ba0a-7061cc9064cd@4g2000yqv.googlegroups.com> <m28v807ec9.fsf@nntp.bednarz.nl> <r1que89eftmfejrieqstmo7bp1ra3e92rv@4ax.com> <m2hamnqzr4.fsf@nntp.bednarz.nl> <b21628e3-149b-41d5-b2a4-5c7efe933984@h2g2000yqa.googlegroups.com> |
| Date | 2013-01-12 02:31 +0100 |
| Message-ID | <m2d2xbi3ub.fsf@nntp.bednarz.nl> (permalink) |
Scott Sauyet <scott.sauyet@gmail.com> 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.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
ScreenName validation "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-08 10:44 -0700
Re: ScreenName validation Scott Sauyet <scott.sauyet@gmail.com> - 2013-01-08 11:02 -0800
Re: ScreenName validation "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-08 13:05 -0700
Re: ScreenName validation Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-11 01:28 +0100
Re: ScreenName validation Jeff North <jnorthau@yahoo.com.au> - 2013-01-11 12:23 +1100
Re: ScreenName validation Stefan Weiss <krewecherl@gmail.com> - 2013-01-11 03:38 +0100
Re: ScreenName validation Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-11 20:35 +0100
Re: ScreenName validation Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-11 21:22 +0100
Re: ScreenName validation Stefan Weiss <krewecherl@gmail.com> - 2013-01-11 22:09 +0100
Re: ScreenName validation Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-11 23:23 +0100
Re: ScreenName validation Stefan Weiss <krewecherl@gmail.com> - 2013-01-12 00:26 +0100
Re: ScreenName validation Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-12 00:54 +0100
Re: ScreenName validation Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-12 00:22 +0100
Re: ScreenName validation Scott Sauyet <scott.sauyet@gmail.com> - 2013-01-11 13:29 -0800
Re: ScreenName validation Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-12 02:31 +0100
csiph-web