Home > Backend Development > PHP Tutorial > 帮忙写个正则匹配,很简单

帮忙写个正则匹配,很简单

WBOY
Release: 2016-06-23 13:56:19
Original
939 people have browsed it

以下是该字符串可能出现的内容
$string ="【灵儿】返现70元";
$string ="前面可能有文字【灵儿】返现70元";
$string ="中间可能是中括号[灵儿]返现70元";

现在需要用正则匹配下,【】或者[]中的内容。


回复讨论(解决方案)

$string =<<< TXT【灵儿】返现70元";前面可能有文字【灵儿】返现70元中间可能是中括号[灵儿]返现70元TXT;preg_match_all('/(\[|【)(.+?)(\]|】)/s', $string, $m);print_r($m[2]);
Copy after login

Array
(
    [0] => 灵儿
    [1] => 灵儿
    [2] => 灵儿
)

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template