ITeye博客

java n正则初步

supben · 2012-08-28 17:27 · JVM · java基础 · 编程语言 · Markdown



// 判断数字
	public static boolean isNumberic(String s) {
		return Pattern.compile("([1-9]+|0)\\.*[0-9]+").matcher(s).matches();
	}

	// 判断邮箱
	public static boolean isEmail(String s) {
		return Pattern.compile("\\w+@{1}\\w+\\.{1}\\w+").matcher(s).matches();
	}

	// 包含某个字符
	public static boolean contains(String s, String c) {
		return Pattern.compile(".*" + c + "+.*").matcher(s).matches();
	}

	// 以某个字符串开头
	public static boolean startWith(String s, String c) {
		return Pattern.compile("^" + c + "\\w*").matcher(s).matches();
	}

	// 以某个字符串结尾
	public static boolean endWith(String s, String c) {
		return Pattern.compile("\\w*" + c + "$").matcher(s).matches();
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。