Using regex to match any character except =

Solution 1:

If the only prohibited character is the equals sign, something like [^=]* should work.

[^...] is a negated character class; it matches a single character which is any character except one from the list between the square brackets. * repeats the expression zero or more times.

Solution 2:

First of all, you don't need a regexp. Simply call contains:

if(str.contains("="))
    System.out.println("does not");
else
    System.out.println("matches");

The correct regexp you're looking for is just

String patternString = "[^=]*";

Solution 3:

If your goal is to not have any = characters in your string, please try the following

String patternString = "[^=]*";

Solution 4:

If you only want to check for occurence of "=" why don't you use the String indexOf() method?

if str.indexOf('=')  //...