问题描述
寻找主机验证正则表达式。
<一个href="http://stackoverflow.com/questions/106179/regular-ex$p$pssion-to-match-hostname-or-ip-address">Regular EX pression匹配主机名或IP地址?
在该链接先生提出了一个像样的正则表达式。我有几个问题/问题与:
- 在Windows计算机/网络名称如
1abcd
允许(核实我们的本地网络) - 在所提出的正则表达式的点可能只出现一次。我认为该
abc.def.gh
是一个有效的主机名还有,是不是。
奇怪,但也没找到可以验证主机名字符串中的任何.NET类(是不是这种情况?)。任何意见将是非常美联社preciated。
更新:任何类/方法的建议 - 请指教东西,将工作无论是在.NET / C#和Silverlight
该点可能会出现不止一次。测试正规前pression 这里,你会看到它匹配。
经常EX pression相关片段(第一部分):
([A-ZA-Z0-9] | [A-ZA-Z0-9] [A-ZA-Z0-9 \ - ] * [A-ZA-Z0 -9])\。)*
从维基百科:
我提到 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 nameslike
1abcd
are allowed (verified onour local network) - In the proposed regex the dot might appear only once. I'd assumethat
abc.def.gh
is a valid hostnameas 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.
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])\.)*
From wikipedia:
I referred to RFC 952. I will try to update the regular expression for hostnames to be compliant with RFC 1123.
这篇关于寻找正则表达式/ code主机名/机器名验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!