To ask a question, does the regular match the database name that created the database SQL?
Consider all cases, as long as the SQL name that can create the database matches.
The name may not have ", there may be no spaces, there may be no modifier keywords, etc...
------Solution--------------------
/create\s+database\s+ (\w+)/is
The name may not have ", there may be no spaces
No possibility
------Solution--------------------
PHP Code
------Solution--------------------
PHP Code
------Solution--------------------
What symbols can appear in the name inside the brackets add to the line like you said () [\w@# ' ()]
I can only guarantee that both sides of the database name appear at the same time ' or do not appear ', cannot control the number of inside '
------Solution--------------------
discuss
That means you can have any character in your name.
No use of the word name can only be used letters and numbers, and the front to add a space and the database text separated.
------Solution--------------------
The string symbol can be expressed in [:p UNCT:], [:p UNCT:] The punctuation character is similar to [: Alnum:] [: space:] ... Each representing several types of strings
You can modify the following
PHP Code
preg_match_all ('/create\s+database\s* ([['] ') '?) ([\w[:p unct:]]+) \2\s?) /is ', $sql, $matchs);
------Solution--------------------
Try
PHP code
$ databases = <<
------Solution--------------------
Not above, ' middle ' must be an even number of bits. This is more troublesome.
------Solution--------------------
discussion
that's right. The ' middle ' is no problem if the even digits match up.
The singular statement is a problematic SQL, no need to consider.
You can't match the AAA ' BBB ' above.
Reference:
not above, ' middle ' must be an even number of bits.
This is more troublesome.