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

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

WBOY
WBOYOriginal
2016-06-23 13:56:19897browse

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

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


回复讨论(解决方案)

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

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

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
Previous article:见鬼啦Next article:TXT 文件操作问题,急