我必須承認,我從來沒有習慣使用正則表達式,但是最近我遇到了一個問題,那裏的解決方案比使用正則表達式更麻煩。我需要能夠匹配任何在字符串開始處遵循以下模式的任何內容: {any_url_safe_word}
+("/http://"
|| "/https://"
|| "www."
)+ {any word}
。 所以下面應該匹配:在URL中匹配特定的正則表達式的話
cars/http://google.com#test
cars/https://google.com#test
cars/www.google.com#test
的follwing不應該匹配:
cars/httdp://google.com#test
cars/http:/google.com#test
我試過到目前爲止:^[\w]{1,500}\/[(http\:\/\/)|(https:\/\/])|([www\.])]{0,50}
,但與從cars/httpd://google.com
cars/http
。
什麼是{any_url_safe_word}? – user4035
例如:cars,ca_rs,ca_1_rs等。不是「c a r s」。 – Babiker