I am working on a project based on WPF,C# and MVVM
. Its basically a networking device configurable application via telnet.I have a following output in my wpf textbox and I want to extract MAC Address column values.
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 cannot use regex because i dont have anything to match.Any help and suggestions would be greatly appreciable.
Depending on where you want to start extraction, use one of these formulas: LEFT function - to extract a substring from the left. RIGHT function - to extract text from the right. MID function - to extract a substring from the middle of a text string, starting at the point you specify.
Extracts the first matching substrings according to a regular expression.
Regular expression matching can be simple and fast, using finite automata-based techniques that have been known for decades. In contrast, Perl, PCRE, Python, Ruby, Java, and many other languages have regular expression implementations based on recursive backtracking that are simple but can be excruciatingly slow.
What's wrong with using a 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 matched MAC addresses.
^\d+\s+(\S+)
You can try this.Grab the capture or group.See demo.
https://regex101.com/r/eZ0yP4/32
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With