startend.java

来自「疯狂Java讲义_源码(含Java设计模式CHM」· Java 代码 · 共 29 行

JAVA
29
字号

import java.util.regex.*; 

/**
 * Description:
 * <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee kongyeeku@163.com
 * @version  1.0
 */

public class StartEnd 
{ 
	public static void main(String[] args)
	{
		String regStr = "Java is very easy!";
		System.out.println("目标字符串是:" + regStr);
		Matcher m = Pattern.compile("\\w+") 
			.matcher(regStr); 
		while(m.find())
		{
			System.out.println(m.group() + "子串的起始位置:" + m.start()
				+ ",其结束位置:" + m.end()); 
		}
	} 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?