Below is my code which allows special characters, numbers, characters(upper and lower) .This program is working fine. My issue with square brackets.
public class MatchingSpecificCharacters {
public static void main(String[] args) {
String reg = "[A-Za-z0-9!$-~`?/@#%^*&()_+=<>.,';:|\" ]*";
String line = "as[]d";
System.out.println(line.matches(reg));
}
}
output
true
In the program, I have used [] brackets to enclose all the characters, numbers , special characters . I have not used extra square brackets to allow as special charters but the program is allowing it. Can anyone tell me why it is allowing square brackets.Correct me If I am wrong.