473,395 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Regular expression capture dependent on token order?

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+fieldNam es='[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 '07 #1
1 1177
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, sthus...@gmail.com 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+fieldNam es='[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 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LuKrOz | last post by:
Someone could tell me how can I get the same result substituting ereg with preg_match and ereg_replace with preg_replace. $result = ereg("<\>(.+)<\>",$this->buffer,$token); $this->buffer =...
5
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
3
by: LordHog | last post by:
Hello all, I am attempting to create a small scripting application to be used during testing. I extract the commands from the script file I was going to tokenize the each line as one of the...
5
by: Cylix | last post by:
I am going to write a function that the search engine done. in search engine, we may using double quotation to specify a pharse like "I love you", How can I using regular expression to sperate...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
5
by: shawnmkramer | last post by:
Anyone every heard of the Regex.IsMatch and Regex.Match methods just hanging and eventually getting a message "Requested Service not found"? I have the following pattern: ^(?<OrgCity>(+)+),...
0
by: altavim | last post by:
Usually when you make regular expression to extract text you are starting from simple expression. When you got to know target text, you are extending your expression. Subsequently very hard to ready...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.