I have a problem with NSRegularExpression. I’m sure that is my mistake, but i can’t figure it out. I have this code:
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern: nextModelName
options:NSRegularExpressionCaseInsensitive
error:&error];
[regex enumerateMatchesInString:objTmplName options:0 range:NSMakeRange(0, [objTmplName length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop){
NSLog(@"objTmplName:%@ nextModelName:%@",objTmplName,nextModelName);
}];
And the output is:
2012-07-30 10:59:48.779 MyApp[8470:707] objTmplName:yaoygo nextModelName:\w*
2012-07-30 10:59:48.799 MyApp[8470:707] objTmplName:yaoygo nextModelName:yo*
2012-07-30 10:59:48.808 MyApp[8470:707] objTmplName:yaoygo nextModelName:yaoygo
Why it get into when objTmplName = yaoygo and nextModelName:yo* ?
What i want to do is when my objTmplName start with “yo…” it will be true, otherway this should be false. For example:
yooygo TRUE
yaygo FALSE
yayoyoyo FALSE
yo*means:yfollowed by any number ofo(possibly none).If you want to force at least one
o, use:After your edit to the question:
try and use the regex:
^yo.*