Home >Backend Development >PHP Tutorial >PHP regular expression problem? ?

PHP regular expression problem? ?

WBOY
WBOYOriginal
2016-08-18 09:15:571078browse

<code class="php">$pattern = "/(abcd){1,2}.*(efgh){1,2}/";
$string = "abcd123efgh456";
preg_match_all($pattern,$string,$result);</code>

PHP regular expression problem? ?

I will write it like this. Put abcd and efgh into the result array. I hope to put abcd into the array instead of putting efgh into the array. How to write this pattern?


Thank you

Reply content:

<code class="php">$pattern = "/(abcd){1,2}.*(efgh){1,2}/";
$string = "abcd123efgh456";
preg_match_all($pattern,$string,$result);</code>

PHP regular expression problem? ?

I will write it like this. Put abcd and efgh into the result array. I hope to put abcd into the array instead of putting efgh into the array. How to write this pattern?


Thank you

(?:abcd)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn