簡體   English   中英

如何修改 URL 正則表達式以匹配 'localhost' 和 'localhost:port'?

[英]How to modify URL regex to also match 'localhost' and 'localhost:port'?

在尋找 URL 驗證的正則表達式時,我發現此示例https://gist.github.com/dperini/729294適合我的需求。 但我還必須驗證true URL,例如http://localhost:5000/#orders:ORD-2http://localhost/#orders:ORD-2 請幫我修改原始正則表達式,以便它可以將普通 URL 和 URL 與localhostlocalhostport匹配。

這個正則表達式可以嗎? 它與您提供的匹配,但我不確定是否需要匹配更多匹配項。

^http:\/\/(localhost|port)(:\d+)?\/#orders:ORD-2$

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM