[英]How can I write a regular expression to match ftp, ftps or sftp?
I'm doing some URL validation and want to match http, https, ftp, ftps, sftp etc. 我正在做一些URL验证,想要匹配http,https,ftp,ftp,sftp等。
So far I have /(https?|ftps?)/
.. If I use s?ftps?
到目前为止,我有
/(https?|ftps?)/
..如果使用s?ftps?
it'll match ftp, ftps, sftp and sftps. 它将匹配ftp,ftps,sftp 和 sftps。
What's the best way to get around this? 什么是最好的解决方法? (sftps is not a valid URL scheme)
(sftps不是有效的URL方案)
Try this: 尝试这个:
/(ht|f)tps?|sftp/
Should work. 应该管用。
这应该覆盖您的所有基地...
/(ht|f)tps?|sftp/
You can use: 您可以使用:
/^(?:ht|f)tps?|sftp/
or 要么
/^(?!sftps)(?:https?|s?ftps?)/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.