6

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.

2
  • You are obviously missing a + after the character class. Commented Aug 23, 2012 at 19:52
  • 2
    Any reason you want to use a regular expression here instead of if (!text.contains("\0"))? Commented Aug 23, 2012 at 19:54

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.