If I may repeat myself "I don't think you need "g" (Global flag) for
this." :)
The reason is, I quote from the doc, "If the g (global) flag is set for
the regular expression, then the search starts at the index position
specified by the lastIndex property of the regular expression. If the
search matches a substring, the lastIndex property changes to match the
position of the end of the match. "
To prove this point, if I do something like:
//
var re:RegExp;
re = new RegExp("The", "gi"); // with global flag
for each(var prop1:XML in testXML.topics.topic){
trace(re.lastIndex, " - ", [EMAIL PROTECTED], " - ",
re["test"]([EMAIL PROTECTED]));
}
trace("***");
re = new RegExp("The", "i"); // without global flag
for each(var prop2:XML in testXML.topics.topic){
trace(re.lastIndex, " - ", [EMAIL PROTECTED], " - ",
re["test"]([EMAIL PROTECTED]));
}
//
I'd get:
0 - Coldplay's New Album, Viva La Vida Or Death And All His Friends -
false
0 - The Dark Knight - true
3 - Arrested Development, The Movie - true
25 - Band Of Horses: Everything All The Time - true
34 - Master And Commander: The Far Side Of The World - true
41 - The Quick Brown Fox Jumped Over The Lazy Dog - false
0 - Violet Hill - false
***
0 - Coldplay's New Album, Viva La Vida Or Death And All His Friends -
false
0 - The Dark Knight - true
0 - Arrested Development, The Movie - true
0 - Band Of Horses: Everything All The Time - true
0 - Master And Commander: The Far Side Of The World - true
0 - The Quick Brown Fox Jumped Over The Lazy Dog - true
0 - Violet Hill - false
With global flag RegExp will not find "the" in "The Quick Brown Fox
Jumped Over The Lazy Dog" because it looks for "the" from the character
41 onwards, namely "Dog", which has no "the".
Kenneth Kawamoto
http://www.materiaprima.co.uk/
Merrill, Jason wrote:
OK, I'm like 95% there, but there is still some kind of bug - here is
how to reproduce:
var testXML:XML = <data>
<topics>
<topic title="Coldplay's New Album, Viva La Vida Or Death And All His
Friends" />
<topic title="The Dark Knight" />
<topic title="Arrested Development, The Movie" />
<topic title="Band Of Horses: Everything All The Time" />
<topic title="Master And Commander: The Far Side Of The World" />
<topic title="The Quick Brown Fox Jumped Over The Lazy Dog" />
<topic title="Violet Hill" />
</topics>
</data>;
var re:RegExp = new RegExp("The", "g,i");
var xmlListSearch:XMLList = testXML..*.topic.( re["test"](
attribute("title")));
trace("result: "+xmlListSearch.toString());
If you search for the word, "the", as I do when I construct the regular
expression, you should get 5 nodes returned into the XMLList, but I only
get these four:
<topic title="The Dark Knight"/>
<topic title="Arrested Development, The Movie"/>
<topic title="Band Of Horses: Everything All The Time"/>
<topic title="Master And Commander: The Far Side Of The World"/>
I don't get this node:
<topic title="The Quick Brown Fox Jumped Over The Lazy Dog" />
????? Any idea why? Does it fail if there is more than one "the" in the
string?
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders