- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个项目,需要验证我的 URL,并偶然发现了以下正则表达式模式;
/(((http|ftp|https):\/{2})+(([0-9a-z_-]+\.)+(aero|asia|biz|cat|com| coop|edu|gov|info|int|jobs|mil|mobi|博物馆|name|net|org|pro|tel|travel|ac|ad|ae|af|ag|ai|al|am|an|ao| aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|通过|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|cz|de|dj|dk|dm| do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm| gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it| je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv| ly|ma|mc|md|me|mg|mh|mk|ml|mn|mn|mo|mp|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne| nf|ng|ni|nl|no|np|nr|nu|nz|nom|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa| re|ra|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy| sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va| vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw|arpa)(:[0-9]+)?((\/([~0-9a -zA-Z\#\+\%@\.\/_-]+))?(\?[0-9a-zA-Z\+\%@\/&\[\];=_-] +)?)?))\b/imuS$/
@ https://mathiasbynens.be/demo/url-regex
这允许我检查前面总是有协议(protocol)的 URL(http、https 或 ftp)。我还想允许用户省略协议(protocol),它仍然有效。我该怎么做?
是否有其他更好/更准确的正则表达式模式可以用来验证我的 URL?感谢您的所有回答!
最佳答案
我目前正在开发一个验证输入的模块。其中一项验证要求我解析域(主机名):
为了验证域名,我采取了几个步骤,其中之一是使用使用这个很酷的技巧来浏览器解析逻辑:
function parseURI( str ) {
var a = document.createElement( "a" );
// If the string doesn't contain a protocol, the browser
// will default to the current document location.
a.href = /^(https?:\/\/)/i.test( str ) === false ? ( "http://" + str ) : str;
// Since I can't overwrite a[property] - return an object I control ( Muahahah ).
return {
hash: a.hash,
hostname: a.hostname,
href: a.href,
origin: a.origin,
pathname: a.pathname,
port: a.port,
protocol: a.protocol,
search: a.search,
// When parsing the URL by the browser fails, the browser will
// set the hostname based on the current document.location value.
valid: a.hostname !== document.location
}
}
如果验证主机名 |域就是您所追求的,我也可以分享我对此主题的见解。
关于javascript - 完美 URL 检查 MOST URL 的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32176201/
为了加速测试字谜字符串的快速输出行为,我 came up with基于质数的哈希方案——尽管它看起来像 I wasn't the first . 基本思想是将字母映射到素数,并计算这些素数的乘积。字母
我使用 Perfect Framework 创建了一个 Swift 3.0 服务器。一切都按预期进行得很好,但我正在尝试了解是否有更好的方法来做一些事情。 来自 iOS 背景,我知道总是在不同的线程中
我有一个固定大小的正方形 div,希望使用 CSS 在其中放置任意大小的图像,以便它在水平和垂直方向上都居中。横向很容易: .container { text-align: center } 对于垂直
程序员离不开终端,配置一个好看又好用的终端,可以提高工作效率. 本篇文章记录了使用 Oh My Zsh + PowerLevel9k + zsh插件 快速配置Ubuntu下默认终端的过程. 我们在
在请求处理程序中,处理例如获取 https://example.com/collections/1或 POSThttp://0.0.0.0:8080/collections 如何获取服务器地址 htt
我正在使用 perfect 和 SQLite司机和StORM作为连接器。我可以一一保存(创建)多行。为了使其更快,我想一次创建多行,我该怎么做? 最佳答案 从完美的 SQLite-StORM 和 Pe
这是我在这里的第一篇文章,所以我希望我提供所有正确的信息。 我目前正在开发一个简单的菜单应用程序,它有一个按钮控制数组(使用 MSDN 建议的控制数组的变通方法),我很难重新调整表单大小和将按钮居中。
在 androidplot XYPlot 中,如果您有较大的值(许多数字)和/或较大的字体大小,则 Y 轴上的刻度标签会被剪裁。这个(以及 X 轴上的类似问题)之前已经在这些问题中讨论过: Range
注意:我遗漏了不相关的代码 所以我目前正在研究 CCC 1996 P1,这个问题的全部目的是能够计算一个整数输入是完美数、不足数还是充数。我上面列出的代码可以工作,但是我认为它太慢了。该代码会迭代每个
我需要什么 我需要一个产生双射输出的算法。我有一个 31 位输入,需要一个伪随机 31 位输出。 我考虑过的 CRC 在其位宽内是双射的。 我查看了 Google 并找到了多项式,但找不到表格或算法。
我在 Ubuntu 14.04.1、clang-3.8 上使用 PerfectSwift我使用的是 Perfect,一切正常,但现在,我不能再编译了(但它可以在我的 mac 上编译) 错误日志是 /h
如果您对分表有以下痛点那么不妨试试我这边开源的框架sharding-core ,是否需要无感知使用分表组件,是否需要支持abp,是否需要支持自定义分表规则,是否需要支持自定义分表键,是否需要支持特定
我正在尝试确定我的 crc 与“ 理想 ”32 位 crc 的比较。 因此,我运行我的 crc 超过 100 万个完全随机的数据样本并收集了碰撞数量,我想将此数字与我可以从“ 理想 ”crc 中预期的
我正在开发一个项目,需要验证我的 URL,并偶然发现了以下正则表达式模式; /(((http|ftp|https):\/{2})+(([0-9a-z_-]+\.)+(aero|asia|biz|cat
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 4 年前。 Improve
我正在创建一个需要居中于中间的圆形网站。背景由围绕中心图像的圆圈组成。每当我以全屏(F11 快捷键)查看我的网站时,无论我的屏幕分辨率如何,它都完美居中。 如果我在没有全屏显示的情况下查看我的网站,我
所以我有一个网站,在开发人员工具中测试响应能力时看起来很棒,但在 iPhone 本身上实际测试时却没有居中并且看起来有些破烂。 什么会导致这种情况,如果我无法使用 iPhone(在我的 android
我有一个内部类,它扩展了 AbstractTableModel。 import javax.swing.table.AbstractTableModel; public class MyClass e
所以我正在使用 Perfect 服务器开发一个将值返回给客户端的应用程序。目前,它需要从另一个 API 下载一些数据,对其进行处理,然后将其发送给客户端。 然而,出于某种原因,它在 OSX 中编译良好
我有一些 CSS 按钮。 “按钮”效果是通过在 anchor 标记中使用固定大小的 元素来完成的,并且 css 规则以 a span:active 、 a span:hover 的形式显示按钮状态。
我是一名优秀的程序员,十分优秀!