Java Code Examples for java.util.regex.Pattern#flags()

The following examples show how to use java.util.regex.Pattern#flags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegularCriterion.java    From caja with Apache License 2.0 6 votes vote down vote up
static RegularCriterion fromPattern(String regex) {
  final Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
  return new RegularCriterion() {
    public String toRegularExpression() {
      StringBuilder sb = new StringBuilder();
      sb.append('/');
      Escaping.normalizeRegex(p.pattern(), sb);
      sb.append('/');
      if ((p.flags() & Pattern.CASE_INSENSITIVE) != 0) { sb.append('i'); }
      return sb.toString();
    }

    public boolean accept(String candidate) {
      return p.matcher(candidate).find();
    }
  };
}
 
Example 2
Source File: RegexReplacer.java    From BungeeChat2 with GNU General Public License v3.0 5 votes vote down vote up
public RegexReplacer(Pattern pattern, String replacement) {
  patternStr = pattern.pattern();
  this.pattern = pattern;
  this.replacement = replacement;

  defaultFlags = pattern.flags();
  patternCache = new HashMap<>();

  patternCache.put(defaultFlags, pattern);
}
 
Example 3
Source File: Filter.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public static IdentifierMatcher createPatternMatcher(final Pattern pattern) {
	return new IdentifierMatcher() {
		public boolean matches(String identifier) {
			if (identifier == null) return false;
			return pattern.matcher(identifier).matches();
		}
		public String toString() {
			return "/" + pattern.pattern() + "/" + pattern.flags();
		}
		public String getSingleString() {
			return null;
		}
	};
}
 
Example 4
Source File: AbstractPatternTextFilter.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private int getPatternFlags(Pattern p) {
	return p == null ? -1 : p.flags();
}
 
Example 5
Source File: TestSingleColumnValueFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
private Filter regexFilterNew(Pattern pattern) {
  return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
  CompareOperator.EQUAL,
      new RegexStringComparator(pattern.pattern(), pattern.flags()));
}
 
Example 6
Source File: JavaCode.java    From RADL with Apache License 2.0 4 votes vote down vote up
private boolean isSingleLinePattern(Pattern pattern) {
  return (pattern.flags() & Pattern.MULTILINE) == 0;
}
 
Example 7
Source File: RegularExpressionElement.java    From mongodb-async-driver with Apache License 2.0 4 votes vote down vote up
/**
 * Converts the {@link Pattern#flags() pattern flags} into a options value.
 * <p>
 * Note that the {@link #VERBOSE} and {@link #LOCALE_DEPENDENT} do not have
 * {@link Pattern} equivalent flags.
 * </p>
 * <p>
 * <blockquote>
 *
 * <pre>
 * {@link Pattern#CASE_INSENSITIVE} ==> {@link #CASE_INSENSITIVE}
 * {@link Pattern#MULTILINE} ==> {@link #MULTILINE}
 * {@link Pattern#DOTALL} ==> {@link #DOT_ALL}
 * {@link Pattern#UNICODE_CHARACTER_CLASS} ==> {@link #UNICODE}
 * </pre>
 *
 * </blockquote>
 *
 * @param pattern
 *            The pattern to extract the options from.
 * @return The options integer value.
 */
protected static int optionsAsInt(final Pattern pattern) {
    int optInt = 0;

    if (pattern != null) {
        final int flags = pattern.flags();
        if ((flags & Pattern.CASE_INSENSITIVE) == Pattern.CASE_INSENSITIVE) {
            optInt |= CASE_INSENSITIVE;
        }
        if ((flags & Pattern.MULTILINE) == Pattern.MULTILINE) {
            optInt |= MULTILINE;
        }
        if ((flags & Pattern.DOTALL) == Pattern.DOTALL) {
            optInt |= DOT_ALL;
        }
        if ((flags & PATTERN_UNICODE) == PATTERN_UNICODE) {
            optInt |= UNICODE;
        }
    }

    return optInt;
}
 
Example 8
Source File: UsageViewPresentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean arePatternsEqual(Pattern p1, Pattern p2) {
  if (p1 == null) return p2 == null;
  if (p2 == null) return false;
  return Comparing.equal(p1.pattern(), p2.pattern()) && p1.flags() == p2.flags();
}
 
Example 9
Source File: UsageViewPresentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static int getHashCode(Pattern pattern) {
  if (pattern == null) return 0;
  String s = pattern.pattern();
  return (s != null ? s.hashCode() : 0) * 31 + pattern.flags();
}