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.)
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:
[$&+,:;=?@#|'<>.^*()%!-]
- 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.
Regex for all special characters
Regex for special characters in java - Stack Overflow
regex - Java Regular expression for special characters across all languages - Stack Overflow
Regex to find special characters in Java - Stack Overflow
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
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 = "[`~!@#$%^&*()_+[\\]\\\\;\',./{}|:\"<>?]";
You may use \\p{Alnum} to match any kind of letter or digit from any language.
private static final String ADDRESS_LINE_PATTERN = "[\\p{Alnum},\\s#\\-.]+";
See Pattern javadoc for more info.
Normally, in Unicode aware regex engines, the word class \w will
include all alpha-num's from any language.
You could use the negative of it \Win a negative class [^\W], add whatever
you don't want _, then OR it with special characters you do want.
(?U)(?:[^\W_]|[-,.+\s#])+
edit - re: @nhahtdh comment
Added Java (?U) inline modifier for UNICODE_CHARACTER_CLASS
(I assume correct)
Try this.
Pattern regex = Pattern.compile("[$&+,:;=?@#|]");
Matcher matcher = regex.matcher("123=456");
if (matcher.find()){
// Do something
}
EDIT: matches() checks all the string and find() finds it in any part of the string.
A link: http://docs.oracle.com/javase/tutorial/essential/regex/index.html
Use String.matches(). Read the Javadocs for supported syntax.