我需要使用正則表達式爲PHP腳本提取Twitter ID。只要在網址中使用雙引號編碼它的偉大工程......使用正則表達式從鏈接中提取單引號和雙引號網址
<a href='http://www.twitter.com/singlequotes'>Twitter Single Quotes</a>
<a href="http://www.twitter.com/doublequotes">Twitter Double Quotes</a>
// regular expression
/<a [^>]*\bhref\s*=\s*"\K[^"]*twitter.com[^"]*/
我一直在使用"|'
,["']
和許多其他的事情,不能工作嘗試。非常感謝,如果你能幫助我。謝謝!
https://regex101.com/r/7Zu3uF/1
但你必須也添加頂點在'[^「]',請參閱https://regex101.com/r/7Zu3uF/2 – horcrux
這很棒,但在我的'preg_match_all(「/ *)* \ bhref \ s * = \ s * ['」] \ K [^ '「] * twitter.com [^'」] */g「,$ result,$ results); 'result in a'Parse error:syntax error,unexpected'「] \ K [^'」'(T_CONSTANT_ENCAPSED_STRING)in ...' – vloryan