寻找正则表达式/ code主机名/机器名验证主机名、机器、正则表达式、code

由网友(我有一颗坚定不移的心)分享简介:寻找主机验证正则表达式。Regular EX pression匹配主机名或IP地址? 在该链接先生提出了一个像样的正则表达式。我有几个问题/问题与:在Windows计算机/网络名称如 1abcd 允许(核实我们的本地网络)在所提出的正则表达式的点可能只出现一次。我认为该 abc.def.gh 是一个有效的主机名...

寻找主机验证正则表达式。

Regular EX pression匹配主机名或IP地址?

在该链接先生提出了一个像样的正则表达式。我有几个问题/问题与:

在Windows计算机/网络名称 如 1abcd 允许(核实 我们的本地网络) 在所提出的正则表达式的点可能只出现一次。我认为 该 abc.def.gh 是一个有效的主机名 还有,是不是。

奇怪,但也没找到可以验证主机名字符串中的任何.NET类(是不是这种情况?)。任何意见将是非常美联社preciated。

更新:任何类/方法的建议 - 请指教东西,将工作无论是在.NET / C#和Silverlight

解决方案   

在所提出的正则表达式的点可能   只出现一次。我认为   abc.def.gh是一个有效的主机名   好了,是吧。

该点可能会出现不止一次。测试正规前pression 这里,你会看到它匹配。

经常EX pression相关片段(第一部分):

 ([A-ZA-Z0-9] | [A-ZA-Z0-9] [A-ZA-Z0-9   - ] * [A-ZA-Z0 -9])。)*
 
怎么查电脑代理服务器的主机名和端口

  

在Windows计算机/网络名称   像1abcd被允许(核实   我们的本地网络)

从维基百科:

  

的原始规格   主机名在 RFC 952 ,强制要求   标签不能以数字开头或   连字符,并不能以结束   连字符。然而,随后的   规范( RFC 1123 )允许   主机名标签,以数字开始。

我提到 RFC 952 。我会尝试更新常规的前pression的主机名要符合 RFC 1123 。

Looking for hostname validation regex.

Regular expression to match hostname or IP Address?

In that link gentlemen propose a decent regex. I have a few problems/questions with that:

On windows computers/networks names like 1abcd are allowed (verified on our local network) In the proposed regex the dot might appear only once. I'd assume that abc.def.gh is a valid hostname as well, isn't it.

Strange, but also couldn't find any .NET class that can validate hostname string (is it the situation?). Any advice will be highly appreciated.

Update: for any class/method proposal - please advice something that will work both in .NET/C# and SilverLight.

解决方案

In the proposed regex the dot might appear only once. I'd assume that abc.def.gh is a valid hostname as well, isn't it.

The dot MAY appear more than once. Test the regular expression here and you will see that it matches.

Relevant fragment of the regular expression (first part is):

([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*

On windows computers/networks names like 1abcd are allowed (verified on our local network)

From wikipedia:

The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits.

I referred to RFC 952. I will try to update the regular expression for hostnames to be compliant with RFC 1123.

阅读全文

相关推荐

最新文章