Skip to content

Commit 15ed8db

Browse files
committed
Backreferences problems
1 parent 0340db3 commit 15ed8db

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.text.*;
4+
import java.math.*;
5+
import java.util.regex.*;
6+
7+
public class Solution {
8+
9+
public static void main(String[] args) {
10+
11+
Regex_Test tester = new Regex_Test();
12+
tester.checker("^\\d{2}(-?)\\d{2}\\1\\d{2}\\1\\d{2}$"); // Use \\ instead of using \
13+
14+
}
15+
}
16+
17+
class Regex_Test {
18+
19+
public void checker(String Regex_Pattern){
20+
21+
Scanner Input = new Scanner(System.in);
22+
String Test_String = Input.nextLine();
23+
Pattern p = Pattern.compile(Regex_Pattern);
24+
Matcher m = p.matcher(Test_String);
25+
System.out.println(m.find());
26+
}
27+
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
$Regex_Pattern = '/^\d{2}(---|-|.|:)\d{2}\1\d{2}\1\d{2}$/'; //Do not delete '/'. Replace __________ with your regex.
4+
5+
$handle = fopen ("php://stdin","r");
6+
$Test_String = fgets($handle);
7+
if(preg_match($Regex_Pattern, $Test_String, $output_array)){
8+
print ("true");
9+
} else {
10+
print ("false");
11+
}
12+
13+
fclose($handle);
14+
?>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
$Regex_Pattern = '/^(\2tic|(tac))+$/'; //Do not delete '/'. Replace __________ with your regex.
4+
5+
$handle = fopen ("php://stdin","r");
6+
$Test_String = fgets($handle);
7+
if(preg_match($Regex_Pattern, $Test_String, $output_array)){
8+
print ("true");
9+
} else {
10+
print ("false");
11+
}
12+
13+
fclose($handle);
14+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.text.*;
4+
import java.math.*;
5+
import java.util.regex.*;
6+
7+
public class Solution {
8+
9+
public static void main(String[] args) {
10+
11+
Regex_Test tester = new Regex_Test();
12+
tester.checker("^([a-z]\\w\\s\\W\\d\\D[A-Z][a-zA-Z][aeiouAEIOU]\\S)\\1$"); // Use \\ instead of using \
13+
14+
}
15+
}
16+
17+
class Regex_Test {
18+
19+
public void checker(String Regex_Pattern){
20+
21+
Scanner Input = new Scanner(System.in);
22+
String Test_String = Input.nextLine();
23+
Pattern p = Pattern.compile(Regex_Pattern);
24+
Matcher m = p.matcher(Test_String);
25+
System.out.println(m.find());
26+
}
27+
28+
}

0 commit comments

Comments
 (0)