I'm using regex to match if a string contains at least an alphabet in it. but when the string contains special characters (not in regular Cp1252 encoding) it is giving me result as not matched even when string is having other alphabets. Here is my code
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringContainsAlphabetsExample {
public static void main(String[] args) {
Pattern pattern = Pattern.compile(".*[a-zA-Z]+.*");
String splChar = "has Alphabet";
Matcher matcher = pattern.matcher(splChar);
if (matcher.matches()) {
System.out.println("Matched");
} else {
System.out.println("Not Matched");
}
}
}
Here is the String that causing error
String splChar = "This text has a special char.
";
Copy and paste the above string in notepad to see the special char.
Please let me know how to filter this special characters in the string or any work around to find if string contains alphabets.