Please go back and edit your post to correct the formatting of your code. Without that the forum software tries to interpret it and removes some characters.
Simply place your cursor on an empty line, click the preformatted text button ( </> ) and then paste your code.
Edited first post as well. I can’t post sample data (work policy), but the instance counts for both patterns occur only 1x in the entire .txt file. Thanks
Hmmm … I don’t know why you again only format just one line of your code and I don’t know how to help you without seeing the input file.
I’d try it with Select-String and providing 2 separate patterns. This way you’ll get the lines of both matches and you can extract all lines between those lines.
Regardless of that I’d recommend to use the -match operator instead of the dot net method. And you could use the method [regex]::Escape() to escape all potentially tricky characters in your patterns.
Edit:
Another tip to develop regex patterns is to use
There you can edit and try this and try that and tweak your patterns until it works as expected.
I agree with Olaf, it would help to see some sample data (just make some up in the same format, you don’t need to share anything work-related) to make the regex match the pattern. You could do it with capture groups, I suppose: