Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex for character code 0 in java

Tags:

java

regex

How does one write a regular expression in java that will match all strings without the character code zero?

I've tried:

Pattern.compile ("[^\0]");

and

Pattern.compile ("[^\u0000]");

Thanks.

like image 758
morfys Avatar asked Aug 23 '12 19:08

morfys


1 Answers

Your first regex is almost right, but it only matches a single character that is not \0. Try changing it to:

Pattern.compile ("[^\0]+");

This should match one-or-more (+) characters that are not \0.

like image 83
newfurniturey Avatar answered Nov 15 '22 10:11

newfurniturey