[英]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.