regex11.java

来自「JAVA 编程思想 第四版 课后习题答案 代码全!」· Java 代码 · 共 22 行

JAVA
22
字号
// strings/RegEx11.java
// TIJ4 Chapter Strings, Exercise 11, page 533
/* Apply the regular expression
*	(?i)((^[aeiou])|(\\s+[aeiou]))\\w+[aeiou]\\b
* 	to
*	Arline ate eight apples and one orange while Anita hadn't any
*/
// (alternate solution) Note double \\ required for \\s+, \\w+ and \\b in compile():

import java.util.regex.*;

public class RegEx11 {
	public static void main(String[] args) {
		Pattern p =
	Pattern.compile("(?i)((^[aeiou])|(\\s+[aeiou]))\\w+[aeiou]\\b");
		Matcher m = p.matcher("Arline ate eight apples and one orange while Anita hadn't any");
		while(m.find())
			System.out.println("Match \"" + m.group() + "\" at " + m.start());
	}
}

⌨️ 快捷键说明

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