regextestharness.java

来自「JAVA 工作指南 可以说是程序员必备的东西哦」· Java 代码 · 共 35 行

JAVA
35
字号
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");            }        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?