正则在java中的应用

package java_07_13;

/**
 * 正则表达式在java中的用法
 * 列举几个常用的方法
 * 其余的api里找吧
 * @author xiao
 * @for training
 */

import java.util.regex.*;

public class RegularExpDemo {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		
		String word = "";//待匹配字符串
		String regular = "";//正则表达式
		Pattern p = Pattern.compile(regular);//建立正则表达式模式
		Matcher m = p.matcher(word);//匹配字符串
		
		m.matches();//尝试将整个字符串与模式匹配
		m.find();//尝试找到与该模式匹配的下一个子序列
		m.group();//返回由以前匹配操作匹配的子序列
		m.replaceAll("");//用给定字符串替换与模式匹配的输入序列的每个子序列
		
	}

}

猜你喜欢

转载自blog.csdn.net/fingers_xwk/article/details/81027323