I have a problem with this code:
textRange = [[html lowercaseString] rangeOfString:[substring lowercaseString]];
I'd like to find some words (substrings) in a HTML page. Using this method, I can find the words that are defined in "substring" but I want to find only entire words which are the substring to be searched for, and not any arbitrary (unbounded) occurrences of the substring. So I tried this method but nothing has changed:
textRange = [html rangeOfString:substring options:NSLiteralSearch];
Here's the entire code:
NSRange textRange;
textRange = [[html lowercaseString] rangeOfString:[substring lowercaseString]];
if (textRange.location != NSNotFound) {
check++;
} else {
// webView.hidden = NO;
}
使用NSRegularExpression
并在模式的开头和结尾包含\\b
以匹配单词边界。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.