File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
core-java-modules/core-java-regex/src/test/java/com/baeldung/regexp Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -70,4 +70,18 @@ public void givenRegexWithDollarEsc_whenReplacing_thenReplace() {
7070
7171 assertEquals (output , m .replaceAll (strReplacement ));
7272 }
73+
74+ @ Test
75+ public void givenStringWithSpecialCharacters_whenUsingCharacterClass_thenReplace () {
76+ String inputString = "#$%^&*() SimpleText123 " ;
77+ StringBuilder escapedString = new StringBuilder ();
78+ for (char c : inputString .toCharArray ()) {
79+ if (!Character .isLetterOrDigit (c )) {
80+ escapedString .append ("\\ " );
81+ }
82+ escapedString .append (c );
83+ }
84+ String expectedOutputString = "\\ #\\ $\\ %\\ ^\\ &\\ *\\ (\\ )\\ SimpleText123\\ " ;
85+ assertEquals (expectedOutputString , escapedString .toString ());
86+ }
7387}
You can’t perform that action at this time.
0 commit comments