将变量粘贴到regexp中
本文关键字:regexp 变量 | 更新日期: 2023-09-27 18:02:02
帮助将变量zone
粘贴到regexp模式。在我看来,我已经尝试了所有可能的变体……总是出现错误!!(这里用静态字符串UntrustGn代替)
List<string> zones = new List<string>
{ "UntrustGi",
"DMZPub",
"DMZMMS",
"DmzGi",
"TrustGi",
"TrustGn",
"DmzGn",
"UntrustGn",
"DMZLOM" };
foreach (string zone in zones)
{
string patternZone = @"set address ""(UntrustGn)"" ("".*"") ([0-9]+.[0-9]+.[0-9]+.[0-9]+)( [0-9]+.[0-9]+.[0-9]+.[0-9]+)";
使用string.Format
,如下:
foreach (string zone in zones) {
string patternZone = string.Format(@"set address ""{0}"" ("".*"") ([0-9]+.[0-9]+.[0-9]+.[0-9]+)( [0-9]+.[0-9]+.[0-9]+.[0-9]+)", zone);
...
}
这样做:
foreach(string zone in zones)
{
string ptternZone = string.Format(@"set address ""{0}"" ("".*"") ([0-9]+.[0-9]+.[0-9]+.[0-9]+)( [0-9]+.[0-9]+.[0-9]+.[0-9]+)", zone);
}
以上使用string.Format
方法