正则(.)*和[.]*
的区别
的区别
解决方案 »
- 求 java就业前景 java就业要求
- 请教: 如何在Jtable中某列使用JList?
- 请问为何出错
- Integer类中toString(int i)方法的(i * 52429)>>>(16+3)的问题
- 为什么???(如下)不可以呢?
- 求救~~~我快被JAVA玩死了~~~
- java模拟先来先服务算法,求大神助我!
- 求解一超级疑难硬盘丢失问题,急啊!!你想不急我能跑这问吗
- 我的APPLET怎么在IE里不能显示啊!
- mybatis中的SynchronizedCache源码遇到的不懂的地方?求大神帮看看
- 帮看一下try{}里的对不对~~~~~~~~~~~~~~~~~~~~~~~~
- java目录分隔符的问题,其中"/"和"//"代表什么意思
找了个例子:import java.io.Console;
import java.util.regex.Pattern;
import java.util.regex.Matcher;public class RegexTestHarness { public static void main(String[] args) {
Console console = System.console();
if (console == null) {
System.err.println("No console.");
System.exit(1);
}
while (true) {
Pattern pattern = Pattern.compile(console.readLine("%nEnter your regex: "));
Matcher matcher = pattern.matcher(console.readLine("Enter input string to search: "));
boolean found = false;
while (matcher.find()) {
console.format("I found the text \"%s\" starting at index %d " +
"and ending at index %d.%n",
matcher.group(), matcher.start(), matcher.end());
found = true;
}
if (!found) {
console.format("No match found.%n");
}
}
}
}out:
Enter your regex: (.)*
Enter input string to search: ddd
I found the text "ddd" starting at index 0 and ending at index 3.
I found the text "" starting at index 3 and ending at index 3.Enter your regex: [.]*
Enter input string to search: ddd
I found the text "" starting at index 0 and ending at index 0.
I found the text "" starting at index 1 and ending at index 1.
I found the text "" starting at index 2 and ending at index 2.
I found the text "" starting at index 3 and ending at index 3.