Why does php regular expression match fail? Help

Source: Internet
Author: User
Tags php regular expression
Why does php regular expression match fail? Help regular php

If (preg_match ("^ [a-zA-Z] [a-zA-Z0-9 _ \-] {5, 19} $", "abc-mmm "))
Echo "true ";
Else echo "false ";

?>

I want to verify the regular expression of the account. it must start with a letter and can contain numbers, letters, underscores, minus signs, and 6-20. why is this expression unsuccessful?

Warning: preg_match () [function. preg-match]: No ending delimiter '^ 'found in test. php on line 3
False

Tried "^ [a-zA-Z] [a-zA-Z0-9 _-] {5, 19} $", get off "\" is not correct, please know (utf8 format)


Reply to discussion (solution)


Preg_match ("/^ [a-zA-Z] [a-zA-Z0-9 _-] {5, 19} $/", "ml-virgil "))


Just try adding "/" before and after, why? I am a beginner in php.

It is called the delimiter. Without the delimiters, PHP determines that ^ [a-zA-Z] [a-zA-Z0-9 _-] {5, 19} $ is a string, not a variable.

We often refer to "\" as "escape character" to escape some special symbols.

It is called the delimiter. Without the delimiters, PHP determines that ^ [a-zA-Z] [a-zA-Z0-9 _-] {5, 19} $ is a string, not a variable. Well, let me ask you a question. I connected English and Chinese to "\ n" and saved it to mysql, php encoding and mysql are both UTF-8. Why does it find "0" in phpadmin and the data type is text? It has been bothering me for a long time...

The SQL statement is really careless. Close the post. thank you.

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.