I have the REGEX below which I am expecting to exclude certain characters. These characters are correctly excluded: £"~#¬|{} but these aren't: @[]/?;:

So, for example, test£test is correctly identified as invalid, but test@test is incorrectly identified as valid.

Testing this on <https://regex101.com/> identifies the problem as the brackets and indicates that I need to escape the first ( [bracket] and the - [hyphen] like this - ^[a-zA-z0-9!$%^&\*\()\-\_=+]+?$. On <https://regex101.com> the expression then behaves as expected but if I try to use escape characters like this in Java the compiler gives an error. 

Any ideas how I can get this regular expression to behave as I want? Sorry if this is obvious. 

```
         final String REGEX = "^[a-zA-z0-9!$%^&*()-_=+]+?$";
         System.out.println ("Please enter a password");
         String password = input.next();
         Pattern p = Pattern.compile(REGEX);
         Matcher m = p.matcher(password);
         if (!m.matches()){
            System.out.println("Illegal characters");

```