To ask a question about a regular match the database name that created the database SQL

Source: Internet
Author: User
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.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.