正则问题

1. 《VB-JS Help.CHM》中文档说“要匹配包括 ' ' 在内的任何字符,请使用象 '[. ]' 的模式”但有些情况这种 '[. ]' 写法并不能准确匹配。这时要用 [sS] 或 [wW]。

2. 正则匹配链接的代码

    //正则匹配单词
    private function regular_dict(&$content){
        $pattern = "/<as([^>]*?)href="([^>]*?)/index.php/Index/Index/search/no/([^>]+?)"([^>]*?)>(w)([^>]*?)</a>/";
        $replace = "<a target="_blank" href="/dict/$5/$5$6.html">$5$6</a>";
        //**/preg_match_all($pattern,$content,$match);
        //**/var_dump($match,$content);die;
        $content = preg_replace($pattern,$replace,$content);
    }

注意,上面的例子 ([^>]*?)

原文地址:https://www.cnblogs.com/chy1000/p/3277199.html