- Java characters that have to be escaped in regular expressions are:
\.[]{}()<>*+-=!?^$| - Two of the closing brackets (
]and}) only have to be escaped after opening the same type of bracket. - In
[]-brackets some characters (like+and-) do sometimes work without escape.
- Java characters that have to be escaped in regular expressions are:
\.[]{}()<>*+-=!?^$| - Two of the closing brackets (
]and}) only have to be escaped after opening the same type of bracket. - In
[]-brackets some characters (like+and-) do sometimes work without escape.
You can look at the javadoc of the Pattern class: http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
You need to escape any char listed there if you want the regular char and not the special meaning.
As a maybe simpler solution, you can put the template between \Q and \E - everything between them is considered as escaped.
Please don't do that... little Unicode BABY ANGELs like this one 👼 are dying! ◕◡◕ (← these are not images) (nor is the arrow!)
☺
And you are killing 20 years of DOS :-) (the last smiley is called WHITE SMILING FACE... Now it's at 263A... But in ancient times it was ALT-1)
and his friend
☻
BLACK SMILING FACE... Now it's at 263B... But in ancient times it was ALT-2
Try a negative match:
Pattern regex = Pattern.compile("[^A-Za-z0-9]");
(this will ok only A-Z "standard" letters and "standard" 0-9 digits.)
You have a dash in the middle of the character class, which will mean a character range. Put the dash at the end of the class like so:
[$&+,:;=?@#|'<>.^*()%!-]
This worked for me:
String result = str.replaceAll("[^\\dA-Za-z ]", "").replaceAll("\\s+", "+");
For this input string:
/-+!@#$%^&())";:[]{}\ |wetyk 678dfgh
It yielded this result:
+wetyk+678dfgh
replaceAll expects a regex:
public static final String specialChars2 = "[`~!@#$%^&*()_+[\\]\\\\;\',./{}|:\"<>?]";
would you say the below is ok to enter in one special character
Regexp('.*[\¬\!\"\£\$\%\^\&\*\(\)\_\+\`\-\=\{\}\:\@\~\<\>\?\[\]\;\'\#\,\.\/\\\|]'
Yes, your expression will match any string that includes at least one of the specified special characters
hi all,
would you say the below is ok to enter in one special character
Regexp('.*[\¬\!\"\£\$\%\^\&\*\(\)\_\+\`\-\=\{\}\:\@\~\<\>\?\[\]\;\'\#\,\.\/\\\|]'
thanks,
rob