You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Deepak MS <me...@gmail.com> on 2015/05/06 15:30:47 UTC

Filtering ArrayCollection using RegExp

Hi there,
I'm trying to filter an AC using RegExp. The requirement is wild character
search. i.e, if I enter 'A*' (asterisk), then I need to display all items
that start with 'A'.

I haven't used RegExps much before. I feel I'm missing something here.
Coudn't get much on net either. Can you kindly help me on this?

This is the code:

if(tiSearch.text.indexOf('*') > -1)
                    {
                        var searchText:String = tiSearch.text.slice(0,
tiSearch.text.length - 1);//trying to remove * and use only the characters
here
                            dataLoader.atcDetailsList.filterFunction =
function wildCardfilterATCs(item:Object):Boolean
                            {
                                var regExp:RegExp = new RegExp(searchText,
"w*");//not working
                                return regExp.test( item['AtcDesc'] );
                            }
                    }else
                    {
                        dataLoader.atcDetailsList.filterFunction = function
filterATCs(item:Object):Boolean
                        {
                            searchText = tiSearch.text
                            var regExp:RegExp = new RegExp( searchText, "i"
); //this works fine, without asterisk. Lists all items that has search
character anywhere in the item.
                            return regExp.test( item['AtcDesc'] );

                        }
                    }

dataLoader.atcDetailsList.refresh();

Re: Filtering ArrayCollection using RegExp

Posted by Deepak MS <me...@gmail.com>.
Hi Kessler,
I didn't knew about that class! It's great. Typically, I wanted 'contains'
, 'starts with' and 'ends with'. All of it is there.
I was using flex 3 in my project. So, i'll just replicate this class in my
project. Thanks again, that was helpful.

Cheers!


On Thu, May 7, 2015 at 4:44 PM, Kessler CTR Mark J <
mark.kessler.ctr@usmc.mil> wrote:

> Try [1] to see if it makes it a little easier assembling a regex pattern.
>  It can create the pattern as a string or create a RegExp with the pattern
> already assembled.
>
>
> RegExPatterns.createRegExp("my search value", RegExPatterns.CONTAINS);
>
> RegExPatterns.createPatternString ("my search value",
> RegExPatterns.CONTAINS);
>
>
> [1]
> https://flex.apache.org/asdoc/spark/components/supportClasses/RegExPatterns.html
>
> -Mark
>

RE: Filtering ArrayCollection using RegExp

Posted by Kessler CTR Mark J <ma...@usmc.mil>.
Try [1] to see if it makes it a little easier assembling a regex pattern.   It can create the pattern as a string or create a RegExp with the pattern already assembled.


RegExPatterns.createRegExp("my search value", RegExPatterns.CONTAINS);

RegExPatterns.createPatternString ("my search value", RegExPatterns.CONTAINS);


[1] https://flex.apache.org/asdoc/spark/components/supportClasses/RegExPatterns.html

-Mark

Re: Filtering ArrayCollection using RegExp

Posted by Deepak MS <me...@gmail.com>.
Hi Alex,
Thank you so much.
First one didn't work, but the second option did.

Yes, regex is quite powerful I believe and surely I'll practice it going
forward. Thanks again.

Cheers!

On Thu, May 7, 2015 at 10:46 AM, Alex Harui <ah...@adobe.com> wrote:

> var regExp:RegExp = new RegExp(searchText, searchText+".*")
>
>
> That doesn’t look right.  I would think it would be:
>    new RegExp(searchText+”.*”, “”)
>
> I think you can also try:
>    new RegExp(“^”+searchText+”.*”, “”)
>
> I think there may be some internet sites where you can practice regex.
>
>
> -Alex
>
> On 5/6/15, 8:50 PM, "Deepak MS" <me...@gmail.com> wrote:
>
> >'A' here would be dynamic. It actually can be anything which user enters
> >in
> >the search text input. Based on your suggestion, I tried this code, still
> >not getting it right:
> >if(tiSearch.text.indexOf('*') > -1)
> >                    {
> >                            var searchText:String = tiSearch.text.slice(0,
> >tiSearch.text.length - 1);
> >                            dataLoader.atcDetailsList.filterFunction =
> >function wildCardfilterATCs(item:Object):Boolean
> >                            {
> >                                var regExp:RegExp = new RegExp(searchText,
> >searchText+".*"); //searchText = 'A'
> >                                return regExp.test( item['AtcDesc'] );
> >                            }
> >                    }
> >
> >If I enter 'A*' it shows me all the items which has 'A' in it irrespective
> >of it's location within the item.
> >
> >On Thu, May 7, 2015 at 12:53 AM, Alex Harui <ah...@adobe.com> wrote:
> >
> >> IIRC, all words starting with A is ‘A.*’
> >>
> >>
> >> On 5/6/15, 6:30 AM, "Deepak MS" <me...@gmail.com> wrote:
> >>
> >> >Hi there,
> >> >I'm trying to filter an AC using RegExp. The requirement is wild
> >>character
> >> >search. i.e, if I enter 'A*' (asterisk), then I need to display all
> >>items
> >> >that start with 'A'.
> >> >
> >> >I haven't used RegExps much before. I feel I'm missing something here.
> >> >Coudn't get much on net either. Can you kindly help me on this?
> >> >
> >> >This is the code:
> >> >
> >> >if(tiSearch.text.indexOf('*') > -1)
> >> >                    {
> >> >                        var searchText:String = tiSearch.text.slice(0,
> >> >tiSearch.text.length - 1);//trying to remove * and use only the
> >>characters
> >> >here
> >> >                            dataLoader.atcDetailsList.filterFunction =
> >> >function wildCardfilterATCs(item:Object):Boolean
> >> >                            {
> >> >                                var regExp:RegExp = new
> >>RegExp(searchText,
> >> >"w*");//not working
> >> >                                return regExp.test( item['AtcDesc'] );
> >> >                            }
> >> >                    }else
> >> >                    {
> >> >                        dataLoader.atcDetailsList.filterFunction =
> >> >function
> >> >filterATCs(item:Object):Boolean
> >> >                        {
> >> >                            searchText = tiSearch.text
> >> >                            var regExp:RegExp = new RegExp( searchText,
> >> >"i"
> >> >); //this works fine, without asterisk. Lists all items that has search
> >> >character anywhere in the item.
> >> >                            return regExp.test( item['AtcDesc'] );
> >> >
> >> >                        }
> >> >                    }
> >> >
> >> >dataLoader.atcDetailsList.refresh();
> >>
> >>
>
>

Re: Filtering ArrayCollection using RegExp

Posted by Alex Harui <ah...@adobe.com>.
var regExp:RegExp = new RegExp(searchText, searchText+".*")


That doesn’t look right.  I would think it would be:
   new RegExp(searchText+”.*”, “”)

I think you can also try:
   new RegExp(“^”+searchText+”.*”, “”)

I think there may be some internet sites where you can practice regex.


-Alex

On 5/6/15, 8:50 PM, "Deepak MS" <me...@gmail.com> wrote:

>'A' here would be dynamic. It actually can be anything which user enters
>in
>the search text input. Based on your suggestion, I tried this code, still
>not getting it right:
>if(tiSearch.text.indexOf('*') > -1)
>                    {
>                            var searchText:String = tiSearch.text.slice(0,
>tiSearch.text.length - 1);
>                            dataLoader.atcDetailsList.filterFunction =
>function wildCardfilterATCs(item:Object):Boolean
>                            {
>                                var regExp:RegExp = new RegExp(searchText,
>searchText+".*"); //searchText = 'A'
>                                return regExp.test( item['AtcDesc'] );
>                            }
>                    }
>
>If I enter 'A*' it shows me all the items which has 'A' in it irrespective
>of it's location within the item.
>
>On Thu, May 7, 2015 at 12:53 AM, Alex Harui <ah...@adobe.com> wrote:
>
>> IIRC, all words starting with A is ‘A.*’
>>
>>
>> On 5/6/15, 6:30 AM, "Deepak MS" <me...@gmail.com> wrote:
>>
>> >Hi there,
>> >I'm trying to filter an AC using RegExp. The requirement is wild
>>character
>> >search. i.e, if I enter 'A*' (asterisk), then I need to display all
>>items
>> >that start with 'A'.
>> >
>> >I haven't used RegExps much before. I feel I'm missing something here.
>> >Coudn't get much on net either. Can you kindly help me on this?
>> >
>> >This is the code:
>> >
>> >if(tiSearch.text.indexOf('*') > -1)
>> >                    {
>> >                        var searchText:String = tiSearch.text.slice(0,
>> >tiSearch.text.length - 1);//trying to remove * and use only the
>>characters
>> >here
>> >                            dataLoader.atcDetailsList.filterFunction =
>> >function wildCardfilterATCs(item:Object):Boolean
>> >                            {
>> >                                var regExp:RegExp = new
>>RegExp(searchText,
>> >"w*");//not working
>> >                                return regExp.test( item['AtcDesc'] );
>> >                            }
>> >                    }else
>> >                    {
>> >                        dataLoader.atcDetailsList.filterFunction =
>> >function
>> >filterATCs(item:Object):Boolean
>> >                        {
>> >                            searchText = tiSearch.text
>> >                            var regExp:RegExp = new RegExp( searchText,
>> >"i"
>> >); //this works fine, without asterisk. Lists all items that has search
>> >character anywhere in the item.
>> >                            return regExp.test( item['AtcDesc'] );
>> >
>> >                        }
>> >                    }
>> >
>> >dataLoader.atcDetailsList.refresh();
>>
>>


Re: Filtering ArrayCollection using RegExp

Posted by Deepak MS <me...@gmail.com>.
'A' here would be dynamic. It actually can be anything which user enters in
the search text input. Based on your suggestion, I tried this code, still
not getting it right:
if(tiSearch.text.indexOf('*') > -1)
                    {
                            var searchText:String = tiSearch.text.slice(0,
tiSearch.text.length - 1);
                            dataLoader.atcDetailsList.filterFunction =
function wildCardfilterATCs(item:Object):Boolean
                            {
                                var regExp:RegExp = new RegExp(searchText,
searchText+".*"); //searchText = 'A'
                                return regExp.test( item['AtcDesc'] );
                            }
                    }

If I enter 'A*' it shows me all the items which has 'A' in it irrespective
of it's location within the item.

On Thu, May 7, 2015 at 12:53 AM, Alex Harui <ah...@adobe.com> wrote:

> IIRC, all words starting with A is ‘A.*’
>
>
> On 5/6/15, 6:30 AM, "Deepak MS" <me...@gmail.com> wrote:
>
> >Hi there,
> >I'm trying to filter an AC using RegExp. The requirement is wild character
> >search. i.e, if I enter 'A*' (asterisk), then I need to display all items
> >that start with 'A'.
> >
> >I haven't used RegExps much before. I feel I'm missing something here.
> >Coudn't get much on net either. Can you kindly help me on this?
> >
> >This is the code:
> >
> >if(tiSearch.text.indexOf('*') > -1)
> >                    {
> >                        var searchText:String = tiSearch.text.slice(0,
> >tiSearch.text.length - 1);//trying to remove * and use only the characters
> >here
> >                            dataLoader.atcDetailsList.filterFunction =
> >function wildCardfilterATCs(item:Object):Boolean
> >                            {
> >                                var regExp:RegExp = new RegExp(searchText,
> >"w*");//not working
> >                                return regExp.test( item['AtcDesc'] );
> >                            }
> >                    }else
> >                    {
> >                        dataLoader.atcDetailsList.filterFunction =
> >function
> >filterATCs(item:Object):Boolean
> >                        {
> >                            searchText = tiSearch.text
> >                            var regExp:RegExp = new RegExp( searchText,
> >"i"
> >); //this works fine, without asterisk. Lists all items that has search
> >character anywhere in the item.
> >                            return regExp.test( item['AtcDesc'] );
> >
> >                        }
> >                    }
> >
> >dataLoader.atcDetailsList.refresh();
>
>

Re: Filtering ArrayCollection using RegExp

Posted by Alex Harui <ah...@adobe.com>.
IIRC, all words starting with A is ‘A.*’


On 5/6/15, 6:30 AM, "Deepak MS" <me...@gmail.com> wrote:

>Hi there,
>I'm trying to filter an AC using RegExp. The requirement is wild character
>search. i.e, if I enter 'A*' (asterisk), then I need to display all items
>that start with 'A'.
>
>I haven't used RegExps much before. I feel I'm missing something here.
>Coudn't get much on net either. Can you kindly help me on this?
>
>This is the code:
>
>if(tiSearch.text.indexOf('*') > -1)
>                    {
>                        var searchText:String = tiSearch.text.slice(0,
>tiSearch.text.length - 1);//trying to remove * and use only the characters
>here
>                            dataLoader.atcDetailsList.filterFunction =
>function wildCardfilterATCs(item:Object):Boolean
>                            {
>                                var regExp:RegExp = new RegExp(searchText,
>"w*");//not working
>                                return regExp.test( item['AtcDesc'] );
>                            }
>                    }else
>                    {
>                        dataLoader.atcDetailsList.filterFunction =
>function
>filterATCs(item:Object):Boolean
>                        {
>                            searchText = tiSearch.text
>                            var regExp:RegExp = new RegExp( searchText,
>"i"
>); //this works fine, without asterisk. Lists all items that has search
>character anywhere in the item.
>                            return regExp.test( item['AtcDesc'] );
>
>                        }
>                    }
>
>dataLoader.atcDetailsList.refresh();