How to extract match string from large text?

I am working on a project based on WPF,C# and MVVM . This is basically a custom network device via telnet. I have the following output in a wpf text box and I want to extract the column values ​​of a MAC address.

 active500EM#sh mac-address-table Read mac address table.... Vlan Mac Address Type Creator Ports ---- --------------------------- ------- ----------------------- 1 00-23-8b-87-9a-6b DYNAMIC Hardware Ethernet1/0/12 1 00-8c-fa-72-94-b1 DYNAMIC Hardware Ethernet1/0/1 1 3c-43-8e-5c-3e-05 DYNAMIC Hardware Ethernet1/0/8 1 d0-59-e4-b9-e9-3e DYNAMIC Hardware Ethernet1/0/8 1 f8-f7-d3-00-03-c0 DYNAMIC Hardware Ethernet1/0/8 1 f8-f7-d3-00-03-f0 STATIC System CPU active500EM# 

I think I can't use regex because I have nothing to match. Any help and suggestions would be very noticeable.

+5
source share
3 answers

What is wrong with regex?

 \b(?<mac_addr>([0-9a-f]{2}-){5}[0-9a-f]{2})\b 

Then you can use:

 var allMacs = Regex.Matches(YOUR_TEXT, REGEX_PATTERN) .Select(m => m.Groups["mac_addr"].Value) .ToList(); 

to get a List<String> with all the negotiated MAC addresses.

+5
source
 ^\d+\s+(\S+) 

You can try this.Grab capture or group.See demo.

https://regex101.com/r/eZ0yP4/32

+2
source

This is a quick regex

 (\w|\d){2}-(\w|\d){2}-(\w|\d){2}-(\w|\d){2}-(\w|\d){2}-(\w|\d){2} 
+1
source

Source: https://habr.com/ru/post/1209326/


All Articles