-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathupper_character
132 lines (104 loc) · 3.37 KB
/
upper_character
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Java program to remove uppercase, lowercase
// special, numeric, and non-numeric characters
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class GFG {
// Function to remove uppercase characters
public static String
removingUpperCaseCharacters(String str)
{
// Create a regular expression
String regex = "[A-Z]";
// Compile the regex to create pattern
// using compile() method
Pattern pattern = Pattern.compile(regex);
// Get a matcher object from pattern
Matcher matcher = pattern.matcher(str);
// Replace every matched pattern with the
// target string using replaceAll() method
return matcher.replaceAll("");
}
// Function to remove lowercase characters
public static String
removingLowerCaseCharacters(String str)
{
// Create a regular expression
String regex = "[a-z]";
// Compile the regex to create pattern
// using compile() method
Pattern pattern = Pattern.compile(regex);
// Get a matcher object from pattern
Matcher matcher = pattern.matcher(str);
// Replace every matched pattern with the
// target string using replaceAll() method
return matcher.replaceAll("");
}
// Function to remove special characters
public static String
removingSpecialCharacters(String str)
{
// Create a regular expression
String regex = "[^A-Za-z0-9]";
// Compile the regex to create pattern
// using compile() method
Pattern pattern = Pattern.compile(regex);
// Get a matcher object from pattern
Matcher matcher = pattern.matcher(str);
// Replace every matched pattern with the
// target string using replaceAll() method
return matcher.replaceAll("");
}
// Function to remove numeric characters
public static String
removingNumericCharacters(String str)
{
// Create a regular expression
String regex = "[0-9]";
// Compile the regex to create pattern
// using compile() method
Pattern pattern = Pattern.compile(regex);
// Get a matcher object from pattern
Matcher matcher = pattern.matcher(str);
// Replace every matched pattern with the
// target string using replaceAll() method
return matcher.replaceAll("");
}
// Function to remove non-numeric characters
public static String
removingNonNumericCharacters(String str)
{
// Create a regular expression
String regex = "[^0-9]";
// Compile the regex to create pattern
// using compile() method
Pattern pattern = Pattern.compile(regex);
// Get a matcher object from pattern
Matcher matcher = pattern.matcher(str);
// Replace every matched pattern with the
// target string using replaceAll() method
return matcher.replaceAll("");
}
// Driver Code
public static void main(String[] args)
{
// Given String str
String str = "GFGgfg123$%";
// Print the strings after the simultaneous
// modifications
System.out.println(
"After removing uppercase characters: "
+ removingUpperCaseCharacters(str));
System.out.println(
"After removing lowercase characters: "
+ removingLowerCaseCharacters(str));
System.out.println(
"After removing special characters: "
+ removingSpecialCharacters(str));
System.out.println(
"After removing numeric characters: "
+ removingNumericCharacters(str));
System.out.println(
"After removing non-numeric characters: "
+ removingNonNumericCharacters(str));
}
}