Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex with all special symbols

Tags:

regex

android

I need regex that will allow only Latin characters, digits and all other symbols(but not whitespace)

thanks!

UPDATE:

private boolean loginPassHasCorrectSymbols(String input){
        if (input.matches("[A-Za-z0-9\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\>\=\?\@\[\]\{\}\\\^\_\`\~]+$")){
            return true;
        }
        return false;
    }
like image 480
Stan Malcolm Avatar asked Sep 25 '15 18:09

Stan Malcolm


2 Answers

I hope I got them all.

"[A-Za-z0-9\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\>\=\?\@\[\]\{\}\\\\\^\_\`\~]+$"

Edit: I forgot that in Java, the regexes are also strings, so you need to actually escape each \ given in the string using another \. I hope I didn't miss any now.

"[A-Za-z0-9\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\>\\=\\?\\@\\[\\]\\{\\}\\\\\\^\\_\\`\\~]+$"
like image 61
BrockLee Avatar answered Oct 12 '22 09:10

BrockLee


How about everything not a whitespace?

"^\S+$"
like image 41
Shawn Mehan Avatar answered Oct 12 '22 09:10

Shawn Mehan