容易 正则表达式

WBOY
Release: 2016-06-13 11:11:20
Original
826 people have browsed it

简单 正则表达式

<br />$ss = "/\[\$?[\w\.]+\]/";<br />preg_match_all($ss, "[abc]", $mat);//[$abc] [abc]为啥匹都配不到<br />
Copy after login


------解决方案--------------------
$ss = "/\[\\$?[\w]+\]/";<br />preg_match_all($ss, '[abc]vv[$def]', $mat);<br />print_r($mat);
Copy after login
Array
(
    [0] => Array
        (
            [0] => [abc]
            [1] => [$def]
        )

)

------解决方案--------------------

引用:
引用:csdn一团糟。。。

$ss = "/\[\\$?[\w\.]+\]/";
或者
$ss = '/\[\$?[\w\.]+\]/';

4 楼
$ss = '/\[\$?[\w\.]+\]/'这个为啥匹配不到[abc]它

为什么不能匹配?
可以匹配啊。你有没试过??
$没转义是指变量。
在“”里 \$ 也是指变量。。。所以你要 \\$ 来转义才是指 "$" 这个字符。
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