/** * Converts a Wildcard search string to REGEX matching whole words in * the text. * @param wildcard the wildcard pattern * @return the regex pattern for the parsed wildcard * @since 0.12.1 */ public static String wildcardWordToRegex(String wildcard){ StringBuilder regex = new StringBuilder("\\b"); encodeWildcard(wildcard, regex); return regex.append("\\b").toString(); } /**
public static String value2Regex(String value){ return '^'+escapeRegex(value)+'$'; } /**
/** * Removes the FieldMapping based on the fieldPattern * @param fieldPattern the field pattern */ public void removeFieldMapping(String fieldPattern){ if(fieldPattern == null || fieldPattern.length()<1){ return; } if(PatternUtils.usesWildCard(fieldPattern)){ Pattern pattern = Pattern.compile(PatternUtils.wildcardToRegex(fieldPattern,true)); synchronized (wildcardMap) { wildcardMap.remove(pattern); } } else { synchronized (fieldMap) { fieldMap.remove(fieldPattern); } } } /* (non-Javadoc)
for (String textConstraint : constraint.getTexts()) { if (textConstraint != null && !textConstraint.isEmpty()) { regexQueryTexts.add(PatternUtils.word2Regex(textConstraint)); for (String textConstraint : constraint.getTexts()) { if (textConstraint != null && !textConstraint.isEmpty()) { regexQueryTexts.add(PatternUtils.wildcardWordToRegex(textConstraint));
/** * Removes the FieldMapping based on the fieldPattern * @param fieldPattern the field pattern */ public void removeFieldMapping(String fieldPattern){ if(fieldPattern == null || fieldPattern.length()<1){ return; } if(PatternUtils.usesWildCard(fieldPattern)){ Pattern pattern = Pattern.compile(PatternUtils.wildcardToRegex(fieldPattern,true)); synchronized (wildcardMap) { wildcardMap.remove(pattern); } } else { synchronized (fieldMap) { fieldMap.remove(fieldPattern); } } } /* (non-Javadoc)
for (String textConstraint : constraint.getTexts()) { if (textConstraint != null && !textConstraint.isEmpty()) { regexQueryTexts.add(PatternUtils.word2Regex(textConstraint)); for (String textConstraint : constraint.getTexts()) { if (textConstraint != null && !textConstraint.isEmpty()) { regexQueryTexts.add(PatternUtils.wildcardWordToRegex(textConstraint));
if(PatternUtils.usesWildCard(fieldPattern)){ this.regex = Pattern.compile(PatternUtils.wildcardToRegex(fieldPattern,true)); this.usesWildcard = true; } else {
public static String value2Regex(String value){ return '^'+escapeRegex(value)+'$'; } /**
/** * Converts a Wildcard search string to REGEX matching whole words in * the text. * @param wildcard the wildcard pattern * @return the regex pattern for the parsed wildcard * @since 0.12.1 */ public static String wildcardWordToRegex(String wildcard){ StringBuilder regex = new StringBuilder("\\b"); encodeWildcard(wildcard, regex); return regex.append("\\b").toString(); } /**
if(PatternUtils.usesWildCard(fieldPattern)){ this.regex = Pattern.compile(PatternUtils.wildcardToRegex(fieldPattern,true)); this.usesWildcard = true; } else {
public static String escapeRegex(String value){ return escapeRegex(value, null).toString(); } /**
/** * Converts a Wildcard search string to REGEX. If strict is enabled, than * the REGEX pattern searches only full labels ("^Patt?er.*$") otherwise * it searches the whole text ("Patt?er.*") * @param wildcard the wildcard pattern * @param strict if <code>true</code> than the REGEX pattern searches * whole words. * @return the pattern */ public static String wildcardToRegex(String wildcard,boolean strict){ StringBuilder regex = new StringBuilder(); if(strict){ regex.append('^'); } encodeWildcard(wildcard, regex); if(strict){ regex.append('$'); } return regex.toString(); }
public static String escapeRegex(String value){ return escapeRegex(value, null).toString(); } /**
/** * Converts a Wildcard search string to REGEX. If strict is enabled, than * the REGEX pattern searches only full labels ("^Patt?er.*$") otherwise * it searches the whole text ("Patt?er.*") * @param wildcard the wildcard pattern * @param strict if <code>true</code> than the REGEX pattern searches * whole words. * @return the pattern */ public static String wildcardToRegex(String wildcard,boolean strict){ StringBuilder regex = new StringBuilder(); if(strict){ regex.append('^'); } encodeWildcard(wildcard, regex); if(strict){ regex.append('$'); } return regex.toString(); }
/** * Creates a regex that matches vales against whole words * ('<code>\b{value}\b</code>) * @param word the word to match * @return the regex to match words * @since 0.12.1 */ public static String word2Regex(String word){ return escapeRegex(word, new StringBuilder("\\b")).append("\\b").toString(); }
/** * Creates a regex that matches vales against whole words * ('<code>\b{value}\b</code>) * @param word the word to match * @return the regex to match words * @since 0.12.1 */ public static String word2Regex(String word){ return escapeRegex(word, new StringBuilder("\\b")).append("\\b").toString(); }