All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.polaris.core.regex.Patterns Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.polaris.core.regex;

import io.polaris.core.map.Maps;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Qt
 * @since 1.8
 */
public class Patterns {

	private static final Map CACHED_PATTERNS = new ConcurrentHashMap<>();

	public static boolean find(String regex, String content) {
		return getPattern(regex).matcher(content).find();
	}

	public static boolean matches(String regex, String content) {
		return getPattern(regex).matcher(content).matches();
	}

	public static Matcher matcher(String regex, String content) {
		return getPattern(regex).matcher(content);
	}

	public static Pattern getPattern(String regex) {
		Pattern pattern = CACHED_PATTERNS.get(regex);
		if (pattern == null) {
			CACHED_PATTERNS.put(regex, pattern = Pattern.compile(regex));
		}
		return pattern;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy