< " I want to check this line containing an ASCII value between 0 ...">

ASCII char with regex (java)

I have a line like message = "ASDF rfghy !@ #$ :>< "

I want to check this line containing an ASCII value between 0 and 255 using regex (java).

+4
source share
3 answers

Just use this code to perform this check:

 System.out.println("Matches: " + message.matches("[\u0000-\u00FF]+")); 
+1
source

You can try regex:

 "^\\p{ASCII}*$" 
+5
source

In regex, \x00 matches the hexadecimal character 00 , and character classes work on them. So you can do:

 /^[\x00-\x7F]+$/ 

to match a string of one or more ascii values.

+2
source

Source: https://habr.com/ru/post/1386045/


All Articles