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

panda.lang.Regexs Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.lang;

import java.util.Collection;
import java.util.regex.Pattern;

public class Regexs {
	public static final String REGEX_URL = "(https?://)?([\\w\\.\\-]+)\\.([a-z\\.]{2,})(/[\\w\\.\\-\\+&%=\\?]*)*";
	public static final String REGEX_EMAIL = "([\\w\\.\\+\\-]+)@([\\w\\.\\-]+)\\.([a-zA-Z\\.]{2,})";
	public static final String REGEX_FILENAME = "[^\\\\/:*?\"<>|]*";

	public static final Pattern PATTERN_URL = Pattern.compile(REGEX_URL, Pattern.CASE_INSENSITIVE);
	public static final Pattern PATTERN_EMAIL = Pattern.compile(REGEX_EMAIL);
	public static final Pattern PATTERN_FILENAME = Pattern.compile(REGEX_FILENAME);

	public static boolean matches(Collection patterns, CharSequence s) {
		if (Collections.isNotEmpty(patterns)) {
			for (Pattern p : patterns) {
				if (p.matcher(s).matches()) {
					return true;
				}
			}
		}
		return false;
	}
	
	public static boolean isURL(String value) {
		return PATTERN_URL.matcher(value).matches();
	}

	public static boolean isEmail(String value) {
		return PATTERN_EMAIL.matcher(value).matches();
	}

	public static boolean isFileName(String value) {
		return PATTERN_FILENAME.matcher(value).matches();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy