Commit a06e491
committed
feat: Remove special characters from a string using regex
- Input: String containing mixed characters including letters, digits, and special symbols (e.g., "a!B@c#1$2%3")
- Applied regex pattern `[^a-zA-Z0-9]` with `replaceAll()` method to remove all characters *except*:
- Lowercase letters (a–z)
- Uppercase letters (A–Z)
- Digits (0–9)
- Replaced disallowed characters with a space to retain readability.
🔍 Explanation:
- `[^a-zA-Z0-9]` is a negated character class, meaning it matches any character *not* in the allowed ranges.
- Useful for sanitizing user input, cleaning noisy strings, or preparing data for processing.
🧪 Example:
- Input: `a!B@c#1$2%3`
- Output: `a B c 1 2 3`
Signed-off-by: Somesh diwan <[email protected]>1 parent 2b94911 commit a06e491
File tree
1 file changed
+8
-10
lines changed- Section6StringClassPrinting/src
1 file changed
+8
-10
lines changedLines changed: 8 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
1 | 9 | | |
2 | 10 | | |
3 | 11 | | |
| |||
6 | 14 | | |
7 | 15 | | |
8 | 16 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
0 commit comments