2
\$\begingroup\$

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!#$%&'()*+,\-./;=?@[\]_~]*)(?::(\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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Many thanks for the help - while I don't necessarily need to support some of those aspects as this is my own internal project, I do appreciate the assistance - especially with the tidbit about hyphens. That I would have never guessed! \$\endgroup\$ – Jeffrey Jan 3 '18 at 5:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.