forked from atuldev19/dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplace_string
51 lines (42 loc) · 1.02 KB
/
replace_string
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Java program for the above approach
import java.util.regex.*;
class GFG {
// Function that checks if a string
// contains uppercase, lowercase
// special character & numeric value
public static void
isAllPresent(String str)
{
// ReGex to check if a string
// contains uppercase, lowercase
// special character & numeric value
String regex = "^(?=.*[a-z])(?=."
+ "*[A-Z])(?=.*\\d)"
+ "(?=.*[-+_!@#$%^&*., ?]).+$";
// Compile the ReGex
Pattern p = Pattern.compile(regex);
// If the string is empty
// then return false
if (str == null) {
System.out.println("No");
return;
}
// Find match between given string
// & regular expression
Matcher m = p.matcher(str);
// Print Yes if string
// matches ReGex
if (m.matches())
System.out.println("Yes");
else
System.out.println("No");
}
// Driver Code
public static void main(String args[])
{
// Given string
String str = "#GeeksForGeeks123@";
// Function Call
isAllPresent(str);
}
}