-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Regex backreferences and assertions problems
- Loading branch information
1 parent
29b7bb0
commit 5198c63
Showing
23 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ | ||
Regex_Test tester = new Regex_Test(); | ||
tester.checker("^\\d{2}(-?)(\\d{2}\\1){2}\\d{2}$"); // Use \\ instead of using \ | ||
|
||
} | ||
} | ||
|
||
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ | ||
Regex_Test tester = new Regex_Test(); | ||
tester.checker("^\\d{2}((-)|(---)|(\\.)|(:))(\\d{2}\\1?){3}$"); // Use \\ instead of using \ | ||
|
||
} | ||
} | ||
|
||
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
|
||
Regex_Test tester = new Regex_Test(); | ||
tester.checker("^(\\2tic|(tac))+$"); // Use \\ instead of using \ | ||
|
||
} | ||
} | ||
|
||
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
|
||
Regex_Test tester = new Regex_Test(); | ||
tester.checker("^([a-z])(\\w)(\\s)(\\W)(\\d)(\\D)([A-Z])([A-Za-z])([AEIOUaeiou])(\\S)\\1\\2\\3\\4\\5\\6\\7\\8\\9\\10$"); // Use \\ instead of using \ | ||
|
||
} | ||
} | ||
|
||
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
|
||
Regex_Test tester = new Regex_Test(); | ||
tester.checker("(.)(?!\\1)"); //Use '\\' instead of '\'. | ||
|
||
} | ||
} | ||
|
||
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); | ||
int Count = 0; | ||
while(m.find()){ | ||
Count += 1; | ||
} | ||
System.out.format("Number of matches : %d",Count); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
|
||
Regex_Test tester = new Regex_Test(); | ||
tester.checker("(?<![aeiouAEIOU])."); //Use '\\' instead of '\'. | ||
|
||
} | ||
} | ||
|
||
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); | ||
int Count = 0; | ||
while(m.find()){ | ||
Count += 1; | ||
} | ||
System.out.format("Number of matches : %d",Count); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
|
||
Regex_Test tester = new Regex_Test(); | ||
tester.checker("o(?=oo)"); //Use '\\' instead of '\'. | ||
|
||
} | ||
} | ||
|
||
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); | ||
int Count = 0; | ||
while(m.find()){ | ||
Count += 1; | ||
} | ||
System.out.format("Number of matches : %d",Count); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
|
||
Regex_Test tester = new Regex_Test(); | ||
tester.checker("(?<=[13579])\\d"); //Use '\\' instead of '\'. | ||
|
||
} | ||
} | ||
|
||
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); | ||
int Count = 0; | ||
while(m.find()){ | ||
Count += 1; | ||
} | ||
System.out.format("Number of matches : %d",Count); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var Regex_Pattern = /(.)(?!\1)/g; //Do not delete `/` and `/g`. | ||
|
||
function processData(Test_String) { | ||
//Enter your code here | ||
var Array = Test_String.match(Regex_Pattern); | ||
console.log("Number of matches :", Array.length); | ||
} | ||
|
||
process.stdin.resume(); | ||
process.stdin.setEncoding("ascii"); | ||
_input = ""; | ||
process.stdin.on("data", function (input) { | ||
_input += input; | ||
}); | ||
|
||
process.stdin.on("end", function () { | ||
processData(_input); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var Regex_Pattern = /o(?=oo)/g; //Do not delete `/` and `/g`. | ||
|
||
function processData(Test_String) { | ||
//Enter your code here | ||
var Array = Test_String.match(Regex_Pattern); | ||
console.log("Number of matches :", Array.length); | ||
} | ||
|
||
process.stdin.resume(); | ||
process.stdin.setEncoding("ascii"); | ||
_input = ""; | ||
process.stdin.on("data", function (input) { | ||
_input += input; | ||
}); | ||
|
||
process.stdin.on("end", function () { | ||
processData(_input); | ||
}); |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Regex_Pattern = r"(.)(?!\1)" # Do not delete 'r'. | ||
|
||
import re | ||
|
||
Test_String = input() | ||
|
||
match = re.findall(Regex_Pattern, Test_String) | ||
|
||
print("Number of matches :", len(match)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Regex_Pattern = r"(?<![aeiouAEIOU])." # Do not delete 'r'. | ||
|
||
import re | ||
|
||
Test_String = input() | ||
|
||
match = re.findall(Regex_Pattern, Test_String) | ||
|
||
print("Number of matches :", len(match)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Regex_Pattern = r'o(?=oo)' # Do not delete 'r'. | ||
|
||
import re | ||
|
||
Test_String = input() | ||
|
||
match = re.findall(Regex_Pattern, Test_String) | ||
|
||
print("Number of matches :", len(match)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Regex_Pattern = r"(?<=[13579])\d" # Do not delete 'r'. | ||
|
||
import re | ||
|
||
Test_String = input() | ||
|
||
match = re.findall(Regex_Pattern, Test_String) | ||
|
||
print("Number of matches :", len(match)) |