DEV Community

cybin
cybin

Posted on

Regex pattern to include needed chars only

I've been asked in a task to make a solution to exclude a list of characters but leaving the normal characters and numbers.

So the following special characters are permitted: "%&$_"

String regexp = "^[a-zA-Z0-9%&$_]*$";
boolean aux = rndmObject.getFileName().matches(regexp);

Hope that this helps someone.

Top comments (0)