我正在尝试了解 java 中正则表达式匹配的工作,并对以下代码片段有疑问
当我运行它时:http: //ideone.com/2vIK77
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.regex.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
String a = "Basic";
String b = "Bas*";
boolean matches = Pattern.matches(b, a);
System.out.println("1) "+matches);
String text2 =
"This is the text to be searched " +
"for occurrences of the pattern.";
String pattern2 = ".*is.*";
boolean matches2 = Pattern.matches(pattern2, text2);
System.out.println("matches2 = " + matches2);
}
}
它在 first 上说 false ,在 second 上说 true 。
1) false
matches2 = true
我无法理解为什么我在第一种情况下会变得错误.. 我希望它是真的。有人可以给我一些建议吗