php preg_mach a mysql db name
Someone please give me a preg
for this
$tbl = '`db_name`.`tbl_name`';
if(preg_match('????',$tbl)){
echo 'ye';
}else{
echo 'no'开发者_Python百科;
}
I need the ????
of preg_match, just so:
- starts with ` (this is the mysql_special comma dont know the name)
- Followed by a-z,number,underscores
followed by ` (mysql)
seperated by (dot) .
- followed by ` (mysql)
- Followed by a-z,number,underscores
- followed by ` (mysql)
preg_match('/^`([a-z0-9_]+)`\\.`([a-z0-9_]+)`$/i', $tbl, $matches);
preg_match('/^`(.*?)`\\.`(.*?)`$/i', $tbl, $matches);
$db = $matches[1];
$table = $matches[2];
This is a little more generic. The .*?
expression will match all characters until it reaches the character that comes after that expression (in this case, the ` character).
精彩评论