正则问题

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

2. 正则匹配链接的代码

    //正则匹配单词
    private function regular_dict(&$content){
        $pattern = "/<a\s([^>]*?)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);
    }

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

posted @ 2013-08-23 11:44  chy1000  阅读(156)  评论(0编辑  收藏  举报