regx, global efficiencies?

Discussion in 'Javascript' started by oldyork90, Jun 9, 2008.

  1. oldyork90

    oldyork90 Guest

    If we toss this in a global area, is it compiled just once one the js
    file is included in the new page?

    var re = /[^\x09-\x0D\x20-\x7E]/o

    Thank you.
     
    oldyork90, Jun 9, 2008
    #1
    1. Advertising

  2. oldyork90

    oldyork90 Guest

    On Jun 9, 5:43 pm, oldyork90 <> wrote:
    > If we toss this in a global area, is it compiled just once one the js
    > file is included in the new page?
    >
    > var re = /[^\x09-\x0D\x20-\x7E]/o
    >
    > Thank you.


    whoops.. this too
    var regex = new RegExp(re);
     
    oldyork90, Jun 9, 2008
    #2
    1. Advertising

  3. oldyork90

    RobG Guest

    On Jun 10, 8:45 am, oldyork90 <> wrote:
    > On Jun 9, 5:43 pm, oldyork90 <> wrote:
    >
    > > If we toss this in a global area, is it compiled just once one the js
    > > file is included in the new page?

    >
    > > var re = /[^\x09-\x0D\x20-\x7E]/o

    >
    > > Thank you.

    >
    > whoops.. this too
    > var regex = new RegExp(re);


    Yes.

    What benefit is there is to calling RegExp as a constructor with re as
    the argument whey you've already initalised re as a regular
    expression. As far as I know, it just creates another instance of re
    (i.e. re is effectively === regexp).

    Oh, there is no 'o' flag, ECMAScript has only g, i and m flags.


    --
    Rob


    --
    Rob
     
    RobG, Jun 10, 2008
    #3
  4. oldyork90 wrote:
    > If we toss this in a global area, is it compiled just once one the js
    > file is included in the new page?
    >
    > var re = /[^\x09-\x0D\x20-\x7E]/o


    It does not compile because `o' is an unsupported flag. Unless, of course,
    you are using an implementation that extends ECMAScript to support it. For
    everything else (including your followup), please read the ECMAScript
    Specification, Edition 3 Final.


    PointedEars
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Jun 10, 2008
    #4
  5. oldyork90

    oldyork90 Guest

    On Jun 9, 7:47 pm, RobG <> wrote:
    > On Jun 10, 8:45 am, oldyork90 <> wrote:
    >
    > > On Jun 9, 5:43 pm, oldyork90 <> wrote:

    >
    > > > If we toss this in a global area, is it compiled just once one the js
    > > > file is included in the new page?

    >
    > > > var re = /[^\x09-\x0D\x20-\x7E]/o

    >
    > > > Thank you.

    >
    > > whoops.. this too
    > > var regex = new RegExp(re);

    >
    > Yes.
    >
    > What benefit is there is to calling RegExp as a constructor with re as
    > the argument whey you've already initalised re as a regular
    > expression. As far as I know, it just creates another instance of re
    > (i.e. re is effectively === regexp).
    >
    > Oh, there is no 'o' flag, ECMAScript has only g, i and m flags.
    >
    > --
    > Rob
    >
    > --
    > Rob


    Thanks Rob. Ok then, 'var re = /[^\x09-\x0D\x20-\x7E]/' is all I
    need. I wasn't sure if that actually
    compiled the expression on not. I thought perhaps all it did was
    assign a string. FYI, that 'o' was a perl
    artifact I guess. Thanks again.
     
    oldyork90, Jun 10, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Victor Bazarov

    Re: code efficiencies with pointers

    Victor Bazarov, Jun 24, 2003, in forum: C++
    Replies:
    0
    Views:
    1,037
    Victor Bazarov
    Jun 24, 2003
  2. dongdong
    Replies:
    2
    Views:
    291
    Paul McGuire
    Mar 25, 2006
  3. werwer

    regx expression? (link included)

    werwer, Feb 2, 2008, in forum: Perl Misc
    Replies:
    2
    Views:
    106
    Brian McCauley
    Feb 2, 2008
  4. Duke of Hazard

    Regx to remove all characters after a match

    Duke of Hazard, Apr 18, 2008, in forum: Perl Misc
    Replies:
    3
    Views:
    179
    Gunnar Hjalmarsson
    Apr 18, 2008
  5. Jake Barnes

    regx for newlines -- var regX = /\\n/g;

    Jake Barnes, Feb 19, 2006, in forum: Javascript
    Replies:
    1
    Views:
    82
    Janwillem Borleffs
    Feb 19, 2006
Loading...

Share This Page