[英]Match all URLs exclude jpg,gif,png
我想匹配所有URL,但從與該正則表達式匹配的beeing中排除圖像URL:jpe?g | gif | png。
\\ b(?:https?| ftp | file):// [-A-Z0-9 +&@#/%?=〜_ | $!:,。;] * A-Z0-9 +&@# /%=〜_ | $
問題是帶有排除項的部分不能像這樣工作:(?!jpe?g | gif | png)
有人對此有解決方案嗎?
例:
不匹配:
http://example.com/example.jpg
http://example.com/example231/example.gif
比賽:
http://example.com/example.html
http://example.com/example/?id=4331
http://example.com/example/example/ex_ample/ex-ample/?id=4331
只需使用(?!.*(?:\\.jpe?g|\\.gif|\\.png)$)
開始您的正則表達式,
因此,如果您當前的正則表達式為\\b(?:https?|ftp|file)://...
,則將其合並到
(?!.*(?:\\.jpe?g|\\.gif|\\.png)$)\\b(?:https?|ftp|file)://...
另請閱讀PHP URL驗證
我正在為一個最近重復的問題解決這個問題,因此我將其發布在這里:
((?!.*(png|jpg|gif)(?!.))(?:https?|file|ftp):\\/\\/.*.\\.(?:com|ca|net|museum|org|co\\.uk))
如果合適,可以隨意添加更多協議,如果合適,可以添加更多圖像擴展,如果合適,可以添加更多頂級域。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.