findWordMatch

This commit is contained in:
Reinhard Pointner 2016-11-06 15:12:22 +08:00
parent 671b680f4b
commit bcabaa61e2
1 changed files with 15 additions and 8 deletions

View File

@ -275,14 +275,21 @@ public class ExpressionFormatMethods {
/**
* Find a matcher that matches the given pattern (case-insensitive)
*/
public static Matcher findMatch(String self, String pattern) {
if (pattern != null) {
Matcher matcher = compile(pattern, CASE_INSENSITIVE | UNICODE_CHARACTER_CLASS).matcher(self);
if (matcher.find()) {
return matcher.reset();
}
}
return null;
public static boolean findMatch(String self, String pattern) {
if (pattern == null || pattern.isEmpty())
return false;
return compile(pattern, CASE_INSENSITIVE | UNICODE_CHARACTER_CLASS).matcher(self).find();
}
/**
* Find a matcher that matches the given pattern (case-insensitive) but matches only if the pattern is enclosed in word-boundaries
*/
public static boolean findWordMatch(String self, String pattern) {
if (pattern == null || pattern.isEmpty())
return false;
return findMatch(self, "\\b(" + pattern + ")\\b");
}
/**