确定字符串是否与模式完全匹配
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main {/** 来自 n o w j a v a . c o m**/ public void main(String[] argv) { String patternStr = "b"; Pattern pattern = Pattern.compile(patternStr); // Determine if there is an exact match CharSequence inputStr = "a b c"; Matcher matcher = pattern.matcher(inputStr); boolean matchFound = matcher.matches(); // false // Try a different input matcher.reset("b"); matchFound = matcher.matches(); // true