繁体   English   中英

有效 web url 和 html 电话 Z572D4E421E5E6B9BC11DZ815EA8 的正则表达式

[英]regex for valid web url and html telephone 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\-\.:\/\$\{\}=\?&#\~]+$/

the above regex should validate both web url and tel url, but it's validating only web url ( https://www.test.com ), which is not validating (tel:23423234)

有人可以帮忙吗?

如果您知道在 href 中永远不会有“<”字符,您可以这样做:

/<a\s+href=["']([^>]+)['"]/i

如果您需要解释,请询问。 我建议使用这个站点来帮助您编写正则表达式字符串。

PS 如果您要匹配的字符串在一行上,请仅使用 ^ 和 $。 我上面的正则表达式适用于<div><a href="tel:15556665872">Click to Call</a></div>之类的示例,但如果我将正则表达式字符串包装在 ^$ 中,则不会。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM