Consider the following text:
{Lorem ipsum dolor sit amet, consectetur adipiscing elit.} {Aenean condimentum lacinia urna quis maximus.} {Nunc mattis elit eget nisi sodales vehicula quis sit amet nulla.} {Nunc molestie ItemKeys:{RED/BLUE/GREEN} erat vitae enim semper volutpat.} {Cras at venenatis urna.} {Nunc nec turpis magna.} {Quisque posuere bibendum sem, in finibus dolor.} {Donec ItemKeys:{YELLOW} lorem eros, eleifend id aliquet id, aliquet non dui.} {Curabitur ac dolor mollis risus euismod sagittis.} {Proin laoreet diam sed dolor malesuada porttitor.} {Orci varius natoque penatibus et ItemKeys:{PURPLE/PINK} magnis dis parturient montes, nascetur ridiculus mus.} {Duis non lobortis turpis.}
Using PowerShell I need to extraxt just the item keys as an array.
RED
BLUE
GREEN
YELLOW
PURPLE
PINK
What would be neatest way to achieve this? I have working code, but it is too unpleasant to think about posting here.
I am using the Regex.Matches method first to handle multiple matches on one line, and the -match operator on each result to get just the colours ($Matches[1]) , and then -split operator to remove the / delimiter. I feel like there should be an easier way, but each regex operator/method seemed to have some limitation. I also looked at Select-String, but the -Raw parameter is not available in PS 5, so just returns the whole string, rather than the matching characters only.
For ref the regex I am using ItemKeys:{([a-zA-Z0-9/]+)}
4