I have a string like "www.mysite.com" in $site variable. In MySQL the Permitted characters in unquoted identifiers are (more info: https://dev.mysql.com/doc/refman/5.7/en/identifiers.html):
- ASCII: [0-9,a-z,A-Z$_] (basic Latin letters, digits 0-9, dollar, underscore)
- Extended: U+0080 .. U+FFFF
However for me now would be enough to do this regular expression: 's/[^0-9a-zA-Z\$]//g'
I would like to replace invalid characters of $site to make valid Schema Object Name (like database name) with underscore. Replace should be done with Perl regex. In this example the . should be replaced with _
In Bash:
site="www.mysite.com"
mysql_db_name= ???
My problem is, that I don't know:
- How to input $site to Perl regexp to do the replacements, then assign result to $mysql_db_name variable?
Thanks!