当前位置: 代码迷 >> Eclipse >> 关于Pattern.matcher(name).matches();的有关问题
  详细解决方案

关于Pattern.matcher(name).matches();的有关问题

热度:155   发布时间:2016-04-23 18:41:11.0
关于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);

}

}
  相关解决方案