我需要使用正則表達式來捕獲href的內容。例如,當我將規則應用於 href =「www.google.com」時,我想要訪問www.google.com。另外,我想忽略所有隻有#值的hrefs。現在獲取href值的內容
,我是打了一段時間,我想出了這個:
href=(?:\"|\')((?:[^#]|.#.|.#|#.)+)(?:\"|\')
當我嘗試一下在http://www.rubular.com/它就像一個魅力,但我需要與preg_replace_callback使用它PHP,在那裏我沒有得到預期的結果(用PHP進行測試,我使用的是這個站點:http://www.pagecolumn.com/tool/pregtest.htm)。
這是什麼錯誤?
首先:不要使用正則表達式來解析HTML(http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self -contained-tags/1732454#1732454) –
已確認;) – misaizdaleka