/*
patString: it$
input: this is it
the output at 2 to the match operation at 1 is false, why?
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.Console;
public class Test {
public static void main(String args[]) {
Console con = System.console();
String patString, input;
patternString = con.readLine("Enter pattern: "); //pattern
input = con.readLine("input: "); // input string to match against pattern
Pattern pattern = Pattern.compile(patString);
Matcher matcher = pattern.matcher(input);
boolean testMatch = matcher.matches(); //1
System.out.println("match found: " + testMatch); //2
}
}
最佳答案
关于java - 与输入匹配时包含 anchor ( $ ) 的正则表达式在以下程序中显示意外结果,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4284106/