replaceFirst的例子

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@SuppressWarnings("all")
public class Run1 {
	public static void main(String[] args) {
		Pattern p = Pattern.compile("john");
		Matcher m = p.matcher("john does this , and john does that");
		String str = m.replaceFirst("sam");
		System.out.println(str);
	}

}

你可能感兴趣的:(原创理论博客)