Regular expression capture dependent on token order?

S

sthussey

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
 
S

Scott

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top