正则表达式匹配简单域 [英] Regex to match simple domain

查看:38
本文介绍了正则表达式匹配简单域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试匹配一个简单的域:example.com

但它的所有组合.

我将如何做到这一点:

<前>https://example.comhttp://www.example.com等等.

解决方案

^https?://([\w\d]+\.)?example\.com$

使用代码:

var 结果 =/^https?:\/\/([a-zA-Z\d-]+\.){0,}example\.com$/.test('https://example.com');//结果为真或假

我改进了它以匹配http://a.b.example.com"

I am trying to match a simple domain: example.com

But all combinations of it.

How would I do this to cover:

https://example.com
http://www.example.com
etc.

解决方案

^https?://([\w\d]+\.)?example\.com$

using code:

var result = /^https?:\/\/([a-zA-Z\d-]+\.){0,}example\.com$/.test('https://example.com');
// result is either true of false

I improved it to match like "http://a.b.example.com"

这篇关于正则表达式匹配简单域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆