Regular expression capture dependent on token order?

Discussion in 'Javascript' started by sthussey@gmail.com, Feb 8, 2007.

  1. Guest

    So I'm trying to write a WDDX deserializer (I know they exist, but I'm
    not fond of what I've seen) and so far everything is hunky dory.
    Rather than writing a full lexical analyzer, I'm just using RE's to
    match the pieces of the WDDX schema that I care about. And everything
    works except for the the recordset element. Below is the string I'm
    trying to match and expression I'm using. The RE matches and populates
    $2 and $3 with the correct captures, but $1 is left undefined. If I
    switch the order of the rowCount and fieldNames attributes of the
    recordset element, then the RE matches and populates all three
    captures correctly. Any ideas?

    var testString = " <recordset rowCount='2'
    fieldNames='FIRST,LAST,AGE'>\n"+
    " <field name='FIRST'><string>Scott</string><string>Jack</
    string></field>\n"+
    " <field name='age'><number>27</number><number>69</number></
    field>\n"+
    " <field name='LAST'><string>Hussey</string><string>Hussey</
    string></field>\n"+
    " </recordset>\n";

    var RE = /^\s*<recordset(?:(\s+rowCount='\d+?')|(\s+fieldNames='[A-Za-
    z0-9,]+?')){2}\s*>((?:.|\s)+?)<\/recordset>/;

    var result = RE.exec(testString);

    // From Firebug:
    // result[0] = entirety of testString
    // result[1] = undefined as above, " rowCount='2'" if I switch the
    rowCont and fieldNames attributes
    // result[2] = " fieldNames='FIRST,LAST,AGE'"
    // result[3] = the string within the recordSet tags
    , Feb 8, 2007
    #1
    1. Advertising

  2. Scott Guest

    So a little more testing shows this to be a bug in the Firefox RE
    engine. It has been reported.

    On Feb 7, 5:38 pm, wrote:
    > So I'm trying to write a WDDX deserializer (I know they exist, but I'm
    > not fond of what I've seen) and so far everything is hunky dory.
    > Rather than writing a full lexical analyzer, I'm just using RE's to
    > match the pieces of the WDDX schema that I care about. And everything
    > works except for the the recordset element. Below is the string I'm
    > trying to match and expression I'm using. The RE matches and populates
    > $2 and $3 with the correct captures, but $1 is left undefined. If I
    > switch the order of the rowCount and fieldNames attributes of the
    > recordset element, then the RE matches and populates all three
    > captures correctly. Any ideas?
    >
    > var testString = " <recordset rowCount='2'
    > fieldNames='FIRST,LAST,AGE'>\n"+
    > " <field name='FIRST'><string>Scott</string><string>Jack</
    > string></field>\n"+
    > " <field name='age'><number>27</number><number>69</number></
    > field>\n"+
    > " <field name='LAST'><string>Hussey</string><string>Hussey</
    > string></field>\n"+
    > " </recordset>\n";
    >
    > var RE = /^\s*<recordset(?:(\s+rowCount='\d+?')|(\s+fieldNames='[A-Za-
    > z0-9,]+?')){2}\s*>((?:.|\s)+?)<\/recordset>/;
    >
    > var result = RE.exec(testString);
    >
    > // From Firebug:
    > // result[0] = entirety of testString
    > // result[1] = undefined as above, " rowCount='2'" if I switch the
    > rowCont and fieldNames attributes
    > // result[2] = " fieldNames='FIRST,LAST,AGE'"
    > // result[3] = the string within the recordSet tags
    Scott, Feb 9, 2007
    #2
    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. Cronus
    Replies:
    1
    Views:
    643
    Paul Mensonides
    Jul 15, 2004
  2. G Fernandes
    Replies:
    1
    Views:
    511
  3. Wessi
    Replies:
    3
    Views:
    830
    Lawrence Kirby
    Aug 11, 2005
  4. =?Utf-8?B?Y2FzaGRlc2ttYWM=?=

    This is an unexpected token. The expected token is 'NAME'

    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=, Jul 13, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    770
    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=
    Jul 13, 2007
  5. puzzlecracker
    Replies:
    1
    Views:
    503
    James Kanze
    Aug 7, 2008
Loading...

Share This Page