Regular expression* problem
益伦
益伦 2017-11-18 09:49:36
0
8
1525

<?php

$zz = '/Audi*/';

##$string = "Audi 2500 is my favorite Love";

if(preg_match($zz, $string, $matches)){

echo 'Matched, the result is: ';

var_dump($matches);

}else{

echo 'No match';

}

? >

Why is the output result 'Audi' instead of 'Audi Audi' or 'Audi Di'? Isn't * at least 0 times? How come not all of them were extracted in two cases?

益伦
益伦

reply all(2)
又白又帅又可爱

Using preg_match should match "Audi", using preg_match_all should match "Audi Audi",

This is a theoretical result, but in fact I have not seen any examples of regular matching in Chinese. Regular It can only check whether it is Chinese and has a limited length, and it uses Chinese bytecode, similar to this: u4e00-u9fa5

  • reply Okay, I tried a lot of Chinese and it really didn’t work. I will use Chinese less as examples in the future.
    益伦 author 2017-11-20 23:17:33
路过

preg_match only matches one

preg_match_all is the entire matching result

It is recommended to check the manual

  • reply &lt;?php $zz = '/250*/'; $string = "Dior and Audi 25000 are my favorites"; if(preg_match($zz, $string, $matches)){ echo 'Matched, the result is:'; var_dump($matches); }else{ echo 'no match'; } ?&gt; It’s getting more and more confusing, so why is the result of this code 25000, not 250 as you said?
    益伦 author 2017-11-18 11:01:48
  • reply Match the character before it any number of times (0 or any number of times)
    益伦 author 2017-11-18 11:08:10
  • reply Okay, thank you for answering
    益伦 author 2017-11-20 23:12:45
  • reply Do you know what * means?
    路过 author 2017-11-18 11:03:33
  • reply Just read the manual
    路过 author 2017-11-18 11:39:39
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template