I have a German-English dictionary of 5-6mb.
- Assuming I store the German words in an array of strings, how do I get "foo", "bar foo" and "foo bar" from the following list of 'words' : "foo","foobar","bar foo","barfoo", "foo bar"
The following code is going to return them all, and if I search for " 开发者_StackOverflowfoo " I don't get "foo"
NSRange r = [word rangeOfString:@".*foo.*" options:NSRegularExpressionSearch];
if (r.location != NSNotFound) {
NSLog(@"%@",word);
}
Try this :
^foo$
When using .*foo.*
, you allow 0 or more characters (.*
) before and after foo
. This is why you get all the strings returned.
精彩评论