There are lot of similar questions on the Regex, however I am still confused on the following case:
import java.util.regex.Pattern;
public class PatternTest {
public static void main(String[] args) {
String PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,20})";
Pattern pattern = Pattern.compile(PATTERN);
boolean isTrue = pattern.matcher("nks#n1Kos2~([{&").matches();
System.out.println(isTrue);
}
}
The characters of ~([{&
is not in the PATTERN, however the matches
shows up true
. What is the reason for that?
Here is a link on Java Regular Expression Tester
https://www.freeformatter.com/java-regex-tester.html#ad-output