我有一个像这样的字符串:A =1
for (i in seq(0.1, 0.3 , by = 0.1)) {
for (j in seq(0.1, 0.3, by = 0.1)) {
for (k in seq(0.1, 0.3, by = 0.1)) {
B = paste("a", i , "b", j, "c",k)
A = c(A, B)
}
}
}
A = A[-1]
A
> A
[1] "a 0.1 b 0.1 c 0.1" "a 0.1 b 0.1 c 0.2" "a 0.1 b 0.1 c 0.3" "a 0.1 b 0.2 c 0.1" "a 0.1 b 0.2 c 0.2" "a 0.1 b 0.2 c 0.3"
[7] "a 0.1 b 0.3 c 0.1" "a 0.1 b 0.3 c 0.2" "a 0.1 b 0.3 c 0.3" "a 0.2 b 0.1 c 0.1" "a 0.2 b 0.1 c 0.2" "a 0.2 b 0.1 c 0.3"
[13] "a 0.2 b 0.2 c 0.1" "a 0.2 b 0.2 c 0.2" "a 0.2 b 0.2 c 0.3" "a 0.2 b 0.3 c 0.1" "a 0.2 b 0.3 c 0.2" "a 0.2 b 0.3 c 0.3"
[19] "a 0.3 b 0.1 c 0.1" "a 0.3 b 0.1 c 0.2" "a 0.3 b 0.1 c 0.3" "a 0.3 b 0.2 c 0.1" "a 0.3 b 0.2 c 0.2" "a 0.3 b 0.2 c 0.3"
[25] "a 0.3 b 0.3 c 0.1" "a 0.3 b 0.3 c 0.2" "a 0.3 b 0.3 c 0.3"
>
我想使用正则表达式从字符串中提取00:1E:AE:4F:20:0BDntl3l
的mac地址,并丢弃00:1E:AE:4F:20:0B
。我如何在C#中实现呢?
我尝试了以下代码,但仍返回相同的字符串。
Dntl3l
答案 0 :(得分:7)
以下对我有用:
google-services.json
但是我个人觉得这有点令人困惑,所以我会做这样的事情:
2018-12-06T17:50:11.193851+00:00 app[web.1]: I, [2018-12-06T17:50:11.193690 #4] INFO -- : [0f0791d6-3aab-4f19-83ad-c421af4a0788] Started GET "/users/edit" for xx.xxx.xxx.xxx at 2018-12-06 17:50:11 +0000
编辑:或者,如果您将两者结合起来:
Started GET "/users/edit" for xx.xxx.xxx.xxx at 2018-12-06 17:50:11 +0000
编辑2:我又想出了另一种使用LINQ和var s = "DSz00:1E:AE:4F:20:0BDntl3l";
var macRegex = "([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}";
var result = Regex.Match(s, macRegex);
Console.WriteLine(result); // 00:1E:AE:4F:20:0B
的{{1}}的方法,尽管我认为这是一个过大的技巧:
var s = "DSz00:1E:AE:4F:20:0BDntl3l";
var hexPair = "[0-9A-Fa-f]{2}";
var macRegex = $"{hexPair}:{hexPair}:{hexPair}:{hexPair}:{hexPair}:{hexPair}";
var result = Regex.Match(s, macRegex);
Console.WriteLine(result); // 00:1E:AE:4F:20:0B