I'm having trouble setting up a RegEx matcher in Android environment.
My String pattern:
private static final String INVALID_PATTERN = "/[^а-яa-z0-9\\s,!\\-_{\\}\\[\\];+]/ig";
Unescaped pattern (matches everything, but cyrillic and latin letters, numbers, space, comma, exclamation mark, minus, underscore, square brackets, semicolon and plus globally ignoring case; I consider those "legal"):
/[^а-яa-z0-9\s,!\-_\[\];+]/ig
My code:
public static ErrorType createStory(@NonNull String name){
Matcher m = Pattern.compile(INVALID_PATTERN).matcher(name);
if(m.matches()){
Log.e("Error", "Story name '" + name + "' contains illegal characters.");
return ErrorType.ILLEGAL;
}
//...
}
This, however, neither throws any errors nor does work.
What I tried so far and didn't work (where string is a String variable):
string.matches(pattern)
Pattern.compile(pattern).matcher(string).matches()