Indeed, the "g" seems to make it not work. Not a big problem, since it's
useless in this case - the "g" flag in a test() call makes the search start
at a specified index (lastIndex property)
What may have confused you, Jason, is the example Robert posted fixed your
problem (by removing the "^" character from the regexp - the "^" when the
first character on a regexp means "match at the start of the line"), and
also added the "g" flag, which is not quite what you wanted. So just drop it
and it will work ;)

Side note: I really hate the re["test"](...) kind of syntax, so here goes my
suggestion:
(re as RegExp).test(...)



On Mon, Jul 21, 2008 at 5:40 PM, Kenneth Kawamoto <[EMAIL PROTECTED]>
wrote:

> I don't think you need "g" (Global flag) for this.
>
> Kenneth Kawamoto
> http://www.materiaprima.co.uk/
>
> Merrill, Jason wrote:
>
>> Wait, think I got it:
>>
>> var re:RegExp = new RegExp(searchInput.text, "g,i");
>>
>> var xmlListSearch:XMLList = testXML..*.( re["test"](
>> attribute("title")));
>>
>> trace("result: "+xmlListSearch.toString());
>>
>> seems to work for me.  Thanks eveyrone!
>>
>> Jason Merrill Bank of America Enterprise Technology & Global Risk L&LD
>> Instructional Technology & Media
>>
>> Join the Bank of America Flash Platform Developer Community
>> Are you a Bank of America associate interested in innovative learning
>> ideas and technologies?
>> Check out our internal  GT&O Innovative Learning Blog & subscribe.
>>
>>
>>> -----Original Message-----
>>>> From: [EMAIL PROTECTED] [mailto:
>>>> [EMAIL PROTECTED] On Behalf Of Robert Leisle
>>>> Sent: Monday, July 21, 2008 3:54 PM
>>>> To: 'Flash Coders List'
>>>> Subject: RE: [Flashcoders] E4X filtering strange behaviour
>>>>
>>>> Hi Jason,
>>>>
>>>> This works for me:
>>>> var testXML:XML = <data>
>>>>                        <topics>
>>>>                                <topic title="Coldplays New Album" />
>>>>                                <topic title="The Dark Knight" />
>>>>                                <topic title="Arrested Development: The
>>>> Movie" />
>>>>                        </topics>
>>>>                </data>;
>>>>
>>>> var re:RegExp = new RegExp(searchInput.text, "g"); var
>>>> xmlListSearch:XMLList = testXML.topics.topic.(re["test"](@title));
>>>> trace("result: "+xmlListSearch.toXMLString());
>>>>
>>>> Hth,
>>>> Bob
>>>>
>>>> -----Original Message-----
>>>> From: [EMAIL PROTECTED]
>>>> [mailto:[EMAIL PROTECTED] On Behalf Of
>>>> Merrill, Jason
>>>> Sent: Monday, July 21, 2008 12:27 PM
>>>> To: Flash Coders List
>>>> Subject: RE: [Flashcoders] E4X filtering strange behaviour
>>>>
>>>> OK, so this is almost there, but not quite.  If I do as Kenneth
>>>> suggested (and this should be able to be reproduced),
>>>> var testXML:XML = <data>
>>>>                        <topics>
>>>>                                <topic title="Coldplays New Album" />
>>>>                                <topic title="The Dark Knight" />
>>>>                                <topic title="Arrested Development: The
>>>> Movie" />
>>>>                        </topics>
>>>>                </data>;
>>>>
>>>> var re:RegExp = new RegExp("^"+searchInput.text); var
>>>> xmlListSearch:XMLList = testXML.topics.topic.(re["test"](@title));
>>>> trace("result: "+xmlListSearch.toXMLString());
>>>>
>>>> (Assuming there is a TextInput text field on the stage and a function
>>>> run when a button is clicked to run the regex search), if I enter the 
>>>> search
>>>> term, "The", it only returns the second node containing "The Dark Knight",
>>>> not the third topic node, which has a "The" in it's title attribute as 
>>>> well.
>>>>  If I put "Dark", it doesn't return anything.  So it seems it's only
>>>> searching nodes where the search term is the first item.
>>>> How can I modify the regular expression above to find all nodes
>>>> containing an element of the search term?
>>>>
>>> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to