-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathforward-references.java
37 lines (28 loc) · 995 Bytes
/
forward-references.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Regex > Backreferences > Forward References
// Back reference to a group which appear later in regex.
//
// https://www.hackerrank.com/challenges/forward-references/problem
// challenge id: 14820
//
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
// (skeliton_head) ----------------------------------------------------------------------
public class Solution {
public static void main(String[] args) {
Regex_Test tester = new Regex_Test();
tester.checker("^(\\2tic|(tac))+$"); // Use \\ instead of using \
}
}
// (skeliton_tail) ----------------------------------------------------------------------
class Regex_Test {
public void checker(String Regex_Pattern){
Scanner Input = new Scanner(System.in);
String Test_String = Input.nextLine();
Pattern p = Pattern.compile(Regex_Pattern);
Matcher m = p.matcher(Test_String);
System.out.println(m.find());
}
}