简体   繁体   中英

Java Regex, All ASCII Except \r and \n

I am trying to check whether or not a string contains valid ASCII characters excluding \\r and \\n . I have \\p{ASCII}+ as the regular expression for valid ASCII, and I have tried [\\p{ASCII}+&&[^\\n\\r]] , but it doesn't seem to work.

You can express your desired set as [\\x00-\\x09\\x0B\\x0C\\x0E-\\x7F] , which is logically the set [\\x00-\\x7F] without newline ( \\x0A ) and carriage return ( \\x0D ).

Since Java supports character set subtraction though, you could also try [\\x00-\\x7F&&[^\\x0A\\x0D]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM