MySQL Connection URI Regular Expression I'm currently working on a project that involves a MySQL database. To make life a little easier, I've been working on a regex that should validate and pull apart the different sections of the connection URI. All of my testing shows that it does work correctly, but I'd like to challenge everyone to see if they can find any errors in the expression.

^(mysqlx?:\/\/)(?:([\w$_]*)(?::([\w$_]+))?@)?([\w!#$%&amp;'()*+,\-./;=?@[\]_~]*)(?::(\d{1,5}))?(?:\/[\w$_])?$


Please note that this regular expression is using the JavaScript regex engine. It was developed in accordance with the MySQL documentation.
Just using your pattern on regex101, against the given examples on the documentation link you provided, the pattern fails for a lot of scenarios.

A few points to consider:


Pattern for valid IPv6 targets
Allow for percent encoding
\- You don't have to escape the hyphen if you move the - (hyphen) at the beginning or the end of matchset so that it does not act as rangeset.
Does not support an attribute in the URI in its current form



  PS: You can test the pattern against the given mysql examples for
  initial validations.