2

How can I extract some parameters from two string and populate the datagrid by them ?

I have the config.txt file and there are two strings are repeated in pairs:

set interface "ethernet1/1.271" tag 271 zone "Ntg-Gom"
set interface ethernet1/1.271 ip 192.168.9.6/30

From this two string i need in extracting ethernet1/1.271 , 271 , 192.168.9.6/30. All this for populating such datagrid:

enter image description here

Obviously, I need a regular expression. Now I have the regexp for one parameter (here ethernet):

StreamReader reader2 = new StreamReader(opendialog.FileName);
string patternI = @"set interface (""ethernet\S+"")";

var matchesI =
Regex.Matches(reader2.ReadToEnd(), patternI).Cast<Match>().Where(m => m.Success)
                        .Select(m => m.Groups[1].Value);

How to construct more complex regexp I do not know! wasting a lot of time...

rene
  • 41,474
  • 78
  • 114
  • 152
user3214034
  • 221
  • 1
  • 6

1 Answers1

2

This will probably do it:

matchResults = Regex.Match(
                 subjectString, 
                 @"""(.*?)""\s+tag\s+(\d+).*?ip\s+([\d./]+)", 
                 RegexOptions.Singleline);
rene
  • 41,474
  • 78
  • 114
  • 152
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268