正则表达式匹配,正则匹配

正则在实际中具备很高的应用价值,学习java最好的网站就是 http://download.oracle.com/javase/tutorial/essential/regex/test_harness.html 下面是一个例子,到处Runnable Jar后运行java –jar XXX.jar就能尝试各种regx了。
import java.io.Console;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class RegexTestHarness {
public static void main(String[] args){
Console console = System.console();
if (console == null) {
System.err.println("No console.");
System.exit(1);
}
while (true) {
Pattern pattern =
Pattern.compile(console.readLine("%nEnter your regex: "));
Matcher matcher =
pattern.matcher(console.readLine("Enter input string to search: "));
boolean found = false;
while (matcher.find()) {
console.format("I found the text \"%s\" starting at " +
"index %d and ending at index %d.%n",
matcher.group(), matcher.start(), matcher.end());
found = true;
}
if(!found){
console.format("No match found.%n");
}
}
}
}
位置关系:
cells正则表达式匹配,正则匹配
Tags:  正则匹配空格 js正则匹配 php正则匹配 正则匹配中文 正则表达式匹配

延伸阅读

最新评论

发表评论