The "." matches any single character but does not limit the string length so 
you would also want to check the length of the string as well.

if(currentID.length == testID.length + 1 && pattern.exec(currentID))


--- In [email protected], "fumeng5" <fume...@...> wrote:
>
> Hi,
> 
> I have a filter function for an array collection that I'm working with. In 
> this scenario, I start with an ID such as '1'. Based on that, I want to 
> return '1_1', '1_2', etc... Basically, an underscore followed by 1 digit. 
> 
> Here's the code:
> 
> var currentID:String = item.id.toString(); // i.e. 1_1, 1_2, etc..
> var testID:String = buttonID + '_'; // buttonID would equal 1
> var pattern:RegExp = new RegExp('^' + testID + "."); 
>             
> if( pattern.exec( currentID ))
>     return true;
> else
>     return false;
> 
> The problem is that this filter is also returning other IDs such as '1_1_2', 
> '1_1_3'. I thought the '.' would limit it 1 character only after the 
> underscore. 
> 
> Can anyone see where I may be going wrong? 
> 
> Thank you!
>


Reply via email to