c# - IP 地址的正则表达式

标签 c# .net regex

我尝试使用以下源代码提取 wan_ip 的值(IP 地址): 怎么了?!我确定 RegEx 模式是正确的。

String input = @"var product_pic_fn=;var firmware_ver='20.02.024';var wan_ip='92.75.120.206';if (parent.location.href != window.location.href)";
Regex ip = new Regex(@"[\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b");
string[] result = ip.Split(input);

foreach (string bla in result)  
{
  Console.WriteLine(bla);                
}

Console.Read();

最佳答案

[ 不应位于模式的开头。此外,您可能想使用 Matches(...)

尝试:

String input = @"var product_pic_fn=;var firmware_ver='20.02.024';var wan_ip='92.75.120.206';if (parent.location.href != window.location.href)";
Regex ip = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b");
MatchCollection result = ip.Matches(input);
Console.WriteLine(result[0]); 

关于c# - IP 地址的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4890789/

相关文章:

c# - 抽象类和接口(interface)有什么区别?

c# - 从 visual studio 和 SQL 中的数据列表中获取选定的产品

c# - 在Windows Docker上安装Matlab

java - 根据数字/字符模式拆分字符串 - Java

创建 scanf 以格式化文本文件

regex - Grep 用于日志文件中的多个单词

时间:2019-05-17 标签:c#fizzbuzzautonumbergenerator

c# - 使用字体对话框更改字体 C#

c# - MVC 网络 API : dot in URL parameter value

.net - 是否有全局命名的读写器锁?