无法为C#中的字符串构建正确的正则表达式
我有一个看起来像这样的字符串:
string str1 = "f1/9999/d1/310822/orig1/GYD/dest1/SAW/f2/7777/d2/300922/orig2/SAW/dest2/GYD";
我正在try 构建一个正则表达式,该表达式将与上面的字符串匹配,但满足以下条件:
(我会将上面的字符串拆分成子字符串,以便更好地解释我需要的内容)
f1- is text that never changing
"9999" should always be a digits and length of this substring may vary from 2-6 characters
"d1"- this text that never changing
"310822" - should always be a digits and length of this substring may vary from 2-6 characters
"orig1" - is text that never changing
"GYD" -should be always be a A-Z characters, length always 3
dest1- this text never changing
"SAW" -should be always be a A-Z characters, length always 3
"f2" -this text that never changing
"7777" - should always be a digits and length of this substring may vary from 2-6 characters
"d2" - this text never changing
"300922" -should always be a digits and length of this substring may vary from 2-6 characters
"orig2" - this text never changing
"SAW" - should be always be a A-Z characters, length always 3
"dest2"-this text never changing
"GYD" -should be always be a A-Z characters, length always 3
另外,所有的斜杠都应该放在正确的位置.
我曾try 构建如下所示的正则表达式,但不起作用:
string str1 = "f1/123456/d1/310822/orig1/GYD/dest1/SAW/f2/7777/d2/300922/orig2/SAW/dest2/GYD";
if (Regex.IsMatch(str1, @"^[f1][/]\d{2,6}[/][d1][/]\d{2,6}[/][orig1][/]\b[a-zA-Z]{3}\b[/][dest1][/]\b[a-zA-Z]{3}\b[/][f2][/]\d{2,6}[/][d2][/]\d{2,6}[/][orig2][/]\b[a-zA-Z]{3}\b[/][dest2][/]\b[a-zA-Z]{3}\b$"))
{
richTextBox1.Text = "true";
}
else { richTextBox1.Text = "false"; }
我总是得到"假的". 您知道如何为字符串str1构建正确的正则表达式吗?