Problems with matches

1

I want to do a match check, which checks that the string contains 5 or more characters that are neither the ñ, nor the z, nor the x. I have tried it in the following way:

b=s.matches("\w{5,}[A-z[^ñzx]][A-z[^ñzx]][A-z[^ñzx]][A-z[^ñzx]][A-z[^ñzx]]");

It does not work like this, I clarify that b is a boolean and s is a String captured on another line.

    
asked by Victor Yil 22.12.2018 в 20:06
source

1 answer

2

depending on the Regular Expression engine this answer is different, I recommend reading this question in StackOverflow in English Exclude characters from a character class , where they give several examples depending on the Regular Expression engine. however given that according to the specific question is with Java. in this case you can use this Regular Expression :

"[\w&&[^ñzx]]{5,}"

that according to the Javadoc of java.util.regex.Pattern indicates:

&& is used for the intersection of two groups in this case the group of \w and [^ñzx] (the latter excludes " ñzx "). therefore:

[\w&&[^ñzx]]{5,} is the same as saying include all word characters ( [a-zA-Z_0-9] ) exept ñ,z,x

    
answered by 23.12.2018 / 03:51
source