Okay, this will be probably a long shot, but I want to understand how it works.
I have a bunch of files that has partially an xml format - since these are not real xmls, Select-Xml and linked cmdlets are not viable options .
However I am looking for some “elements” in the files, for this I am using the script of:
There are no duplicates. You have two separate independent patterns. Each pattern will produce a match. So you have in one file one match for the pattern <logicalIdentifier> and one match for the pattern <status>.
Depending on what you need the data for you could use
I used the regex class matches method, which will find all occurrences of matching text.
I used named “capture groups” for readability. Iterate the captures, pull the groups object (like a dictionary) and pull the ‘Identifier’ property. It’s only named that because of the named capture group.
The pattern matches <status> and then any number of characters .+ but the shortest amount of characters ? that’s what this pattern here is combined .+? Without some stopping marker, it would match the rest of all the text. This says match until you encounter the character <
I encourage you to check out this regex demo and also use this site to learn more about regex. Regex can be used almost everywhere, so it is beneficial outside of powershell as well.