本帖最后由 刘忠德 于 2011-12-25 07:45 编辑
package com.cupfish.test;
import java.util.regex.*;
public class Regex {
public static void main(String[] args){
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args[1]);
System.out.println("Pattern is " + m.pattern());
while(m.find()){
System.out.println(m.start() + " " + m.end() + " " + m.group());
}
}
}
调用:
java Regex "a?" "aba"
结果为:
Pattern is a?
0 1 a
1 1
2 3 a
3 3
1 1和3 3就是零长度匹配,不太理解,求助ing...
|
|