[英]Detect FQDN and URL REGEX MATCH (Javascript)
這與我之前發布的問題無關。 我需要一個正則表達式來檢測FDQN,例如google.ca/和www.google.ca/(必須檢測正斜杠)以及url(例如http://www.google.ca和https://www.stackoverflow) .com 。 有人可以幫我弄這個嗎。 我正在使用match(在javascript中)檢測這些FDQN和URL。 抱歉,這似乎是我上一個問題的重復,但不是(更具體)。
我正在使用它來匹配Twitter的字符數。 當他們檢測到URL或FDQN時,會將URL(如果是https)壓縮為21個字符,將其他字符壓縮為20個字符(無論長度如何)。
是“ google.ca/”完整域名嗎? 我想是的,即使這也解決了http:// uz /問題,實際上是您到底在搜索什么? :)
檢查這是否適合您: http : //regexlib.com/redetails.aspx?regexp_id=1735&AspxAutoDetectCookieSupport=1
如果不是這樣,regexplib.com是一個很好的來源,但是我建議您更精確/明確地定義您的需求。
您可以使用來檢測到任何東西.
並且沒有空格,但是可能會導致誤報。
例如。
var s = "This is not related to a previous question I posted. I need a regex to detect FDQN such as google.ca/ and www.google.ca/ (must detect the forward slash) as well as urls such as http://www.google.ca and https://www.stackoverflow.com. Can someone help me with this"
console.log(s.match(/(https?\:\/\/)?([a-z0-9\-]+\.)+[a-z0-9\-]{2,8}\/?/ig))
輸出量
[
"google.ca/",
"www.google.ca/",
"http://www.google.ca",
"https://www.stackoverflow.com"
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.