package javase1.day01;
02
03 import java.util.Scanner;
04 import java.util.regex.Matcher;
05 import java.util.regex.Pattern;
06
07 public class RegexTestHarnessV5 {
08
09 public static void main(String[] args) {
10 Scanner scanner = new Scanner(System.in);
11 while (true) {
12 System.out.printf("%nEnter your regex: ");
13 Pattern pattern = Pattern.compile(scanner.nextLine());
14 System.out.printf("Enter input string to search: ");
15 Matcher matcher = pattern.matcher(scanner.nextLine());
16 boolean found = false;
17 while (matcher.find()) {
18 System.out.printf("Found \"%s\" starting index %d ending index %d.%n",
19 matcher.group(), matcher.start(), matcher.end());
20 found = true;
21 }
22 if (!found) {
23 System.out.printf("No match found.%n");
24 }
25 }
26 }
27 }
02
03 import java.util.Scanner;
04 import java.util.regex.Matcher;
05 import java.util.regex.Pattern;
06
07 public class RegexTestHarnessV5 {
08
09 public static void main(String[] args) {
10 Scanner scanner = new Scanner(System.in);
11 while (true) {
12 System.out.printf("%nEnter your regex: ");
13 Pattern pattern = Pattern.compile(scanner.nextLine());
14 System.out.printf("Enter input string to search: ");
15 Matcher matcher = pattern.matcher(scanner.nextLine());
16 boolean found = false;
17 while (matcher.find()) {
18 System.out.printf("Found \"%s\" starting index %d ending index %d.%n",
19 matcher.group(), matcher.start(), matcher.end());
20 found = true;
21 }
22 if (!found) {
23 System.out.printf("No match found.%n");
24 }
25 }
26 }
27 }