cancel
Showing results for 
Search instead for 
Did you mean: 

RegEx Negation of whole word

Former Member
0 Kudos

Hi everybody,

I have problems to find a fitting RegEx for the following:

strInput = "elvis";
regex = "^e^l^v^i^s";
		if (strInput.matches(regex)) {
			System.out.println("Hit: " + strInput);
		} else {
			System.out.println("No hit for: " + strInput + " regex" + regex);
		}

I want to check if a String is unequal to "elvis"

The above coding does not work?

e.G. if you use "x_elvis" instead of "elvis", it should match

Thanks

Regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Mario,

try this:


  regex = "^$|^[^e].*|^e$|^e[^l].*|^el$|^el[^v].*|^elv$|^elv[^i].*|^elvi$|^elvi[^s].*|^elvis.+";

The character ^ means "beginning-of-line" when not in brackets; in brackets it means negation.

Best regards,

Jens

Answers (1)

Answers (1)

Former Member
0 Kudos

Thank you all