List of usage examples for java.util.regex Pattern pattern
pattern
From source file:com.iorga.webappwatcher.util.PatternListParameterHandler.java
@Override protected String convertToString(final List<Pattern> value) { if (value == null) { return ""; }/* www .j ava 2s . c om*/ final StringBuilder stringBuilder = new StringBuilder(); boolean first = true; for (final Pattern pattern : value) { if (!first) { stringBuilder.append(','); } else { first = false; } stringBuilder.append(pattern.pattern()); } return stringBuilder.toString(); }
From source file:de.undercouch.bson4jackson.serializers.BsonSerializersTest.java
/** * Tests {@link BsonRegexSerializer}//from w ww .ja v a2s .c om * @throws Exception if something goes wrong */ @Test public void regex() throws Exception { Pattern pat = Pattern.compile("[a-zA-Z0-9]+"); Pattern obj = (Pattern) generateAndParse(pat); assertEquals(pat.pattern(), obj.pattern()); }
From source file:info.magnolia.cms.filters.AbstractMgnlFilter.java
public Collection<String> getMappings() { ArrayList<String> result = new ArrayList<String>(); for (Pattern pattern : getMapping().getMappings()) { result.add(pattern.pattern()); }/* w ww.ja v a 2 s .c o m*/ return result; }
From source file:com.ibm.watson.catalyst.jumpqa.matcher.EntryPatterns.java
private boolean patternsEqual(Optional<Pattern> op1, Optional<Pattern> op2) { if (op1.isPresent() ^ op2.isPresent()) return false; if (op1.isPresent() & op2.isPresent()) { Pattern p1 = op1.get(); Pattern p2 = op2.get();//ww w .j av a 2 s .c om if (!Objects.equals(p1.pattern(), p2.pattern())) return false; if (!Objects.equals(p1.flags(), p2.flags())) return false; } return true; }
From source file:de.undercouch.bson4jackson.deserializers.BsonDeserializersTest.java
/** * Tests if {@code Pattern} objects can be deserialized * @throws Exception if something goes wrong *///from www.j ava 2 s .c o m @Test public void regex() throws Exception { Pattern pat = Pattern.compile("[a-zA-Z0-9]+"); TC.R obj = generateAndParse(pat, TC.R.class); assertEquals(pat.pattern(), obj.obj.pattern()); }
From source file:org.gradle.util.NameMatcher.java
/** * Locates the best match for the given pattern in the given set of candidate items. * * @return The match if exactly 1 match found, null if no matches or multiple matches. */// w w w . j av a 2 s . c om public String find(String pattern, Collection<String> items) { this.pattern = pattern; matches.clear(); candidates.clear(); if (items.contains(pattern)) { matches.add(pattern); return pattern; } if (pattern.length() == 0) { return null; } Pattern camelCasePattern = getPatternForName(pattern); Pattern normalisedCamelCasePattern = Pattern.compile(camelCasePattern.pattern(), Pattern.CASE_INSENSITIVE); String normalisedPattern = pattern.toUpperCase(); Set<String> caseInsensitiveMatches = new TreeSet<String>(); Set<String> caseSensitiveCamelCaseMatches = new TreeSet<String>(); Set<String> caseInsensitiveCamelCaseMatches = new TreeSet<String>(); for (String candidate : items) { if (candidate.equalsIgnoreCase(pattern)) { caseInsensitiveMatches.add(candidate); } if (camelCasePattern.matcher(candidate).matches()) { caseSensitiveCamelCaseMatches.add(candidate); continue; } if (normalisedCamelCasePattern.matcher(candidate).lookingAt()) { caseInsensitiveCamelCaseMatches.add(candidate); continue; } if (StringUtils.getLevenshteinDistance(normalisedPattern, candidate.toUpperCase()) <= Math.min(3, pattern.length() / 2)) { candidates.add(candidate); } } if (!caseInsensitiveMatches.isEmpty()) { matches.addAll(caseInsensitiveMatches); } else if (!caseSensitiveCamelCaseMatches.isEmpty()) { matches.addAll(caseSensitiveCamelCaseMatches); } else { matches.addAll(caseInsensitiveCamelCaseMatches); } if (matches.size() == 1) { return matches.first(); } return null; }
From source file:org.tightblog.rendering.comment.BlacklistCommentValidator.java
private boolean isBlacklisted(List<Pattern> combinedRules, String textToCheck) { if (!StringUtils.isEmpty(textToCheck)) { for (Pattern testPattern : combinedRules) { Matcher matcher = testPattern.matcher(textToCheck); if (matcher.find()) { log.debug("{} matched by {}", matcher.group(), testPattern.pattern()); return true; }/*from ww w .j a v a 2s . co m*/ } } return false; }
From source file:mitm.common.dlp.impl.PolicyPatternImpl.java
public void setPattern(Pattern pattern) { this.pattern = pattern; regExp = pattern != null ? pattern.pattern() : null; }
From source file:org.jboss.windup.interrogator.util.KnownArchiveProfiler.java
public boolean isKnownVendor(ZipMetadata archive, String pkg) { for (Pattern cbl : knownPackages.keySet()) { if (cbl.matcher(pkg).find()) { if (LOG.isDebugEnabled()) { LOG.debug("Found known package: " + pkg + " matching: " + cbl.pattern()); }/*from www . j a v a 2 s. co m*/ String vendor = knownPackages.get(cbl); VendorResult vr = new VendorResult(); vr.setDescription(vendor); archive.getDecorations().add(vr); return true; } } return false; }
From source file:org.loklak.susi.SusiLog.java
public void removeUnanswered(Pattern p) { if (this.unanswered == null) getUnanswered();/*from www.ja v a 2s . c o m*/ if (dnruset.contains(p.pattern())) return; boolean removed = this.unanswered.remove(p.pattern()); if (!removed) { Iterator<String> i = this.unanswered.iterator(); while (i.hasNext()) { String s = i.next(); if (p.matcher(s).matches()) { i.remove(); removed = true; } } } if (removed) System.out.println("** removed unanswered " + p.pattern()); }