im trying to learn about regex, and how to use it braking up som logs and populating som textboxes with the results.
if i have a simple line like this
Port status: tro-S-02-av1 0/23
and want to put the tro-S-02-av1 and the 0/23 in a variable
all names wold end on av1 so the regular exspression shold be based on this.
i was thinking like this to try to get the string of tro-S-02-av1 to become the value a text box but i cant get it right, how can i do this.
Regex r;
Match m;
r = new Regex("$`\av1");
m = r.Match("Port status: tro-S-02-av1 0/23");
nodetbx.Text = m.Value;
Using groups with the following regex (for example, you could probably clean this up)
Will give you two named groups, ID1 and ID2 you can then populate.
I found using named groups easier when first learning regex so you can really see what’s going on.
Take a look at nregex to help practice and test regexs too.
Where MyText is either each line looping through the file with ReadLine or the whole file if not too big.
You can then use ID1 and ID2 (renamed to something meaningful) to populate textbox or whatever.