pattern.compile,patterncompiler
java中关于Pattern的一个方法
你的用法有问题,spilt()方法是用来分割字符串的,而你想要的结果应该是匹配字符串,匹配应该用find(),group(),如下:
public
static
void
main(String[]
args)
{
Pattern
p
=
Pattern.compile("\\w{3}");
String
matchedString
=
"qwedfg";
//
重新给出待匹配的字符序列
Matcher
m
=
p.matcher(matchedString);
String[]
a
=
p.split(matchedString);
while(m.find())
{
System.out.println(m.group());
}
}
输出结果为:
qwe
dfg
spilt()方法的试用实例:
public
static
void
main(String[]
args)
{
Pattern
p
=
Pattern.compile(",");
String
matchedString
=
"abc,def,asdf,aer,wtw,sfa";
//
重新给出待匹配的字符序列
String[]
a
=
p.split(matchedString);
System.out.println(a.length);
for(int
i=0;ia.length;i++)
{
System.out.println(a[i]);
}
}
输出结果为:
6
abc
def
asdf
aer
wtw
sfa

Pattern p1 = Pattern.compile("a*b"); Matcher
第一个是将正则表达式赋予pattern对象
第二个是匹配第一个中的中正则表达式
Java中Pattern pattern = Pattern.compile("(\\d)*");正则表达式的含义是什么?
将给定的正则表达式(\d出现0到多)编译到具有给定标志的模式中。
Pattern p = Pattern .compile("[create table](\\p{Blank})([a-zA-Z]+)\\((.+)\\)");
java.util.regex.Pattern
正则表达式的一种已编译的实现。
下面是一个典型的调用次序:
Pattern p = Pattern.compile("a*b");
Matcher m = p.matcher("aaaaab");
boolean b = m.matches();
也可以合起来写:
boolean b = Pattern.matches("a*b", "aaaaab");
等价于上面的三个句子
至于正则表达式的含义,貌似是个建表语句的sql吧·····