Afamee Afamee - 2 months ago 17
Java Question

How to escape a square bracket for Pattern compilation

I have comma separated list of regular expressions:

.{8},[0-9],[^0-9A-Za-z ],[A-Z],[a-z]

I have done a split on the comma. Now I'm trying to match this regex against a generated password. The problem is that
does not like square brackets that is not escaped. Can some please give me a simple function that takes a string like so:
and returns the escaped string


You can use Pattern.quote(String).