带有所有特殊符号的正则表达式

Sta*_*olm 3 regex android

我需要只允许使用拉丁字符,数字和所有其他符号的正则表达式(但不能使用空格)

谢谢!

更新:

private boolean loginPassHasCorrectSymbols(String input){
        if (input.matches("[A-Za-z0-9\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\>\=\?\@\[\]\{\}\\\^\_\`\~]+$")){
            return true;
        }
        return false;
    }
Run Code Online (Sandbox Code Playgroud)

Leo*_*Han 5

我希望我都明白了。

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

编辑:我忘记了在Java中,正则表达式也是字符串,因此您实际上需要\使用another 来转义字符串中的每个给定\。我希望我现在没有错过任何机会。

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