javascript - 有效网页 url 和 html 电话 url 的正则表达式
问题描述
**https://www.test.com**
I have written regex for the above url like below
/^\{[\$\w][\$\w\.\[\]]+\}|^https{0,1}:\/\/[\w\-\.:\/\$\{\}=\?&#\~]+$/
now i am trying to add **tel:15556665872** condition to the above regex like below
/^\{[\$\w][\$\w\.\[\]]+\} |^tel{0,1}:[\d]+ |^https{0,1}:\/\/[\w\-\.:\/\$\{\}=\?&#\~]+$/
上面的正则表达式应该验证 web url 和 tel url,但它只验证 web url ( https://www.test.com ),而不是验证 (tel:23423234)
有人可以帮忙吗?
解决方案
如果您知道在 href 中永远不会有“<”字符,您可以这样做:
/<a\s+href=["']([^>]+)['"]/i
如果您需要解释,请询问。我建议使用这个站点来帮助您编写正则表达式字符串。
PS 如果您要匹配的字符串在一行上,请仅使用 ^ 和 $。我上面的正则表达式适用于类似的例子,<div><a href="tel:15556665872">Click to Call</a></div>
但如果我将我的正则表达式字符串包装在 ^$ 中,它就不会。
推荐阅读
- flutter - Flutter 驱动程序处理最小化的应用程序
- terraform - 如果存在现有资源,则将其用作数据
- python - 一次生成 numpy 数组元素的组合,并且在运行中
- java - 沿 @ConfigurationProperties 的通用对象
- java - 如何从 Android 中的均衡器获取更新的音轨?
- php - Symfony 3.4 功能测试
- python-3.x - 有没有与此错误相关的解决方案?
- python - 将函数中的循环设置为不同的线程python
- angular - 带有 fromgroup 的 ngbDatepicker 无法预设值(本机日期)
- shell - 如何在shell中的特定字符后剪切字符串?