Ask for a regular match, there's a little doubt

Source: Internet
Author: User
 
  

Solve, thank you.


Reply to discussion (solution)

Old, Donald, and so on, can't pass the old word.
The rules are: $pre = '/old/';
Preg_match returns the number of matches to 0 or 1, which only performs a match once
'/[\'\"\ \ ]/'
This rule is to find, single quotation marks, double quotes, half space, full-width space, these four sets, as long as there is any one, do not pass, in addition to the single quotation mark to add \ Escape, the other can not add

Specify the encoding

$pre = '/[\ ' \ ' \ \]/u ';

$str = ' Donald Duck '; $pre = '/[\ ' \ \ \]/', if (Preg_match ($pre, $str)) {    echo $str. ' Not passed ';} else{    echo $str. ' Through ';}
Donald Duck Through
$str = ' Donald Duck '; $pre = '/[\ ' \ \ \]/', if (Preg_match ($pre, $str)) {    echo $str. ' Not passed ';} else{    echo $str. ' Through ';}
Donald doesn't pass.

I don't know what you're going to do.

$str = ' Donald Duck '; $pre = '/[\ ' \ \ \]/', if (Preg_match ($pre, $str)) {    echo $str. ' Not passed ';} else{    echo $str. ' Through ';}
Donald Duck Through
$str = ' Donald Duck '; $pre = '/[\ ' \ \ \]/', if (Preg_match ($pre, $str)) {    echo $str. ' Not passed ';} else{    echo $str. ' Through ';}
Donald doesn't pass.

I don't know what you're going to do.



Sorry, my question is not clearly expressed.
is to detect whether the $STR string contains the single quotation marks in the $pre, and so on, the expression does not pass, does not pass.
For example: $str = ' Hello ' can be passed
$str = ' Hello ' there is no space between the two words.
But I found $str= ' Donald Duck ' or $str= ' old ' couldn't pass, and two didn't contain half-width white space full-width single quotation marks, very strange why?
Thank you.

Old, Donald, and so on, can't pass the old word.
The rules are: $pre = '/old/';
Preg_match returns the number of matches to 0 or 1, which only performs a match once
'/[\'\"\ \ ]/'
This rule is to find, single quotation marks, double quotes, half space, full-width space, these four sets, as long as there is any one, do not pass, in addition to the single quotation mark to add \ Escape, the other can not add


Sorry, my question is not clearly expressed.
is to detect whether the $STR string contains the single quotation marks in the $pre, and so on, the expression does not pass, does not pass.
For example: $str = ' Hello ' can be passed
$str = ' Hello ' there is no space between the two words.
But I found $str= ' Donald Duck ' or $str= ' old ' couldn't pass, and two didn't contain half-width white space full-width single quotation marks, very strange why?
Thank you.

No, what's wrong with my two test results?

No, what's wrong with my two test results?


I didn't get the first one here, and I don't know why.


No, what's wrong with my two test results?


I didn't get the first one here, and I don't know why.


Remove the full-width space in the $pre to

#2 should have been said, Utf-8 code to add a U property


No, what's wrong with my two test results?


I didn't get the first one here, and I don't know why.

#2 should have been said, Utf-8 code to add a U property



No, what's wrong with my two test results?


I didn't get the first one here, and I don't know why.


Okay thank you

Specify the encoding

$pre = '/[\ ' \ ' \ \]/u ';


Thank you

If I solve this, do not want to use regular ~ to provide a way of thinking under discussion
Code rough not tested, there are errors please forgive

$str = ' Tang Lao ' duck '; $search = Array (', ', '); The character to be detected $replace = '; Disable the word embox into spaces $str = Str_replace ($search, $replace, $str), if (Strpos ($str, ')!== false) {//To determine if there is no space    Echo ' does not pass ';}

Leaving the editor is true to the colours

  • Related Article

    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.