import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class TestRegex {
public static void main(String[] args) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String input = "input", regex = "regex";
Pattern p;
Matcher m; while (!input.equals("")) {
try {
System.out.print("Input: \n");
input = in.readLine();
System.out.print("Regular expression: \n");
regex = in.readLine();
} catch (IOException e) {
e.printStackTrace();
} p = Pattern.compile(regex);
m = p.matcher(input);
while (m.find()) {
System.out.println("Match \"" + m.group() + "\" at positions " +
m.start() + "-" + (m.end() - 1));
}
}
}
}命令行的,将就用吧...
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class TestRegex {
public static void main(String[] args) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String input = "input", regex = "regex";
Pattern p;
Matcher m; while (!input.equals("")) {
try {
System.out.print("Input: \n");
input = in.readLine();
System.out.print("Regular expression: \n");
regex = in.readLine();
} catch (IOException e) {
e.printStackTrace();
} p = Pattern.compile(regex);
m = p.matcher(input);
while (m.find()) {
System.out.println("Match \"" + m.group() + "\" at positions " +
m.start() + "-" + (m.end() - 1));
}
}
}
}命令行的,将就用吧...
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货