首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java模式匹配的有关问题

2012-12-20 
java模式匹配的问题import java.io.Consoleimport java.util.regex.Matcherimport java.util.regex.Patt

java模式匹配的问题
import java.io.Console;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexText {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
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:"));
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");
}
}

}

}

上面的程序运行的结果是No console 不能匹配输入的字符串,但又没找的原因,哪位指点一下,谢谢

热点排行