Filter array using pattern

I have an array of words(all the words are in NSMutableArray). I need to filter the words as shown below.

???? - Any four letter word ma?t* - Any word that starts with the letters “ma” and has a “t” as the forth letter. z - Any word that contains the letter “z” ?n?t? - Any five letter word with ”n” as the second letter and “t” as the forth letter. *s*b* - Any word that contains the letter “s” and then the letter “b” in the remaining letters. mouth  - The word “moth” will be returned if it exists in the current Word List t*s? - Any words that start with the letter “t” , is at least three letters long and has “s” as the second last letter in the word. * - Returns all words in the Word List.

Answers


you can use the below code for filter using pattern

-(NSMutableArray *)searchByPattern:(NSString *)patternString inputArray:(NSMutableArray *)inputArray
{
    NSLog(@"orginal Array count=%d",[inputArray count]);
    NSString *match=[NSString stringWithFormat:@"%@",patternString];
    NSLog(@"match = %@",match);
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF like %@",match];    
    NSMutableArray *mArrayFiltered = [[inputArray filteredArrayUsingPredicate:predicate] mutableCopy];
    //NSLog(@"mArrayFiltered = %@ count = %d",mArrayFiltered,[mArrayFiltered count]);
    return mArrayFiltered;
}

Need Your Help

Breaking String

iphone

I have to break this string in two parts: 2º Felipe Massa (BRA)

Why can't I insert the same ID into the 'id' column of my MySQL table?

php mysql phpmyadmin

I'm creating a messaging system and I'm trying to set it up so it will have a "conversation view" and so users can reply to a message. To do this I have to have a primary ID for each conversation i...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.