扫码一下
查看教程更方便
Regex 类 matches() 方法尝试将整个区域与模式匹配。
public boolean matches()
无
当且仅当整个区域序列与此匹配器的模式匹配时才为true。
import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatcherDemo { private static final String REGEX = "foo"; private static final String INPUT = "fooooooooooooooooo"; private static Pattern pattern; private static Matcher matcher; public static void main( String args[] ) { pattern = Pattern.compile(REGEX); matcher = pattern.matcher(INPUT); System.out.println("Current REGEX is: "+REGEX); System.out.println("Current INPUT is: "+INPUT); System.out.println("lookingAt(): "+matcher.lookingAt()); System.out.println("matches(): "+matcher.matches()); } }
上面示例编译运行结果如下
Second Capturing Group, (foo) Match String end(): 3
Second Capturing Group, (foo) Match String end(): 9
Second Capturing Group, (foo) Match String end(): 14