question

YaroC-2432 avatar image
0 Votes"
YaroC-2432 asked YaroC-2432 answered

Selecting from text with select-string

I'm trying to find all occurrences of following pattern [int]$license in a script located on multiple machines. When I run $test | select-string -pattern '/[int/]' where $test holds the content of the file, this works as long as I won't add the dollar sign afterwards. I tried '/[int/]/$license' and '/[int/]`$license' but neither works which proves my regex is useless :) Can someone help with this?

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

In a regex the escape character is "\", not "/".

 $test = 'write-host "bogus!" [int]$license Some Other stuff'
 $test -match '\[int\]\$license'
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
0 Votes"
cooldadtx answered

Try this $test | select-string -pattern '\[int\]\$license'

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YaroC-2432 avatar image
0 Votes"
YaroC-2432 answered

Indeed. Silly as it is it was the wrong character I was trying to use.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.