I need to validate a in a method like this.
validateFileName(Editable s) {
String filtered_str = s.toString();
if (filtered_str.matches(".*[regexp].*")) {
filtered_str = filtered_str.replaceAll("[regxp]", "");
s.clear();
s.append(filtered_str);}
Which regexps should i use to exclude all illegal characters and white-spaces? I’m using linux
If your idea is only to exclude ilegal and space char you can use something like:
'^[^*&%\s]+$'where you can add any “ilegal” char into the list of chars (in this case it ignores *, &, % and space)
\sis the space! The^inside the[]is part of the regex syntax it means: do not match any chars inside[].