---
title: "java n正则初步"
author: "supben"
date: "2012-08-28T17:27:49Z"
tags: []
categories: ["编程语言"]
slug: "java-n"
draft: false
lastmod: "2012-08-28T17:27:49Z"
id: 1665568
url: "https://supben.iteye.com/blog/1665568"
---

```java


// 判断数字
	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();
	}

```