读书人

关于Pattern.matcher(name).matches()

发布时间: 2012-01-05 22:36:54 作者: rapoo

关于Pattern.matcher(name).matches();的问题。
Pattern.matcher(name).matches();报这样的错误,can 't make a static reference to the non-static method matcher(charsequerence) from the type Pattern.请高手指点我一下。急,谢谢!

[解决办法]
正则的用法:
Pattern pattern = Pattern.compile(...);
Matcher m = pattern.matcher(...);
[解决办法]
import java.util.regex.*;

class Regex1{

public static void main(String args[]) {

String str= "For my money, the important thing "+

"about the meeting was bridge-building ";

String regEx= "a|f "; //表示a或f

Pattern p=Pattern.compile(regEx);

Matcher m=p.matcher(str);

boolean result=m.find();

System.out.println(result);

}

}

读书人网 >Eclipse开发

热点推荐