[thelist] New JS/HTML/CSS IDE

Lee kowalkowski lee.kowalkowski at googlemail.com
Fri Nov 10 09:47:42 CST 2006


On 09/11/06, Max Schwanekamp <lists at neptunewebworks.com> wrote:
> > From: Randal Rust
> > > Tom
> > > 43 % Nerd, 60% Geek, 17% Dork
> >
> > 100% helpful:)
>
> Er, 110%...?

Eh? 120%!  - but Geek != Nerd == false.  I.e. Nerd, Geek and Dork
aren't necessarily mutually exclusive.  I could be 66% Hairy and 72%
Biker, bad example, because I'm not a hairy biker.

I would have replied sooner, but was trying to think of a decent tip...

<tip
  type="Reusing Regular Expression objects in JavaScript"
  author="Lee Kowalkowski"
>

You might never encounter this, but if you do, you'll appreciate it.

    var genericRE = /a/g; // trivialised example, matches all
occurrences of 'a'.
    alert(genericRE.test("cba")); // returns true.
    alert(genericRE.test("abc")); // returns false.

Why does the second test return false?  Well, because the first call
to test modifies the lastIndex property of the Regular Expression
object.

The next time you call test it will continue to search from this
point, even when testing a different string.

    var genericRE = /a/g; // trivialised example, matches all
occurrences of 'a'.
    alert(genericRE.test("cba")); // returns true.
    genericRE.lastIndex = 0; // reset search.
    alert(genericRE.test("abc")); // returns true.

</tip>

-- 
Lee



More information about the thelist mailing list