g0mez
g0mez

Reputation: 55

Powershell string in pattern

i writing small script in Powershell and i have no idea for another steps...

I have array with:

$666 = "abrakadabra","blabla/blabla","blabla/abraka_dabra(20_10_2015).bla"

In file saved on HDD, i have file, named as content.txt. In this file i need find string from array. With "abrakadabra" and "blabla/blabla" i dont have problems, but with "blabla/abraka_dabra(20_10_2015).bla" yes.

As part of script i triing this with:

foreach ( $line in $666 ) { select-string content.txt -pattern $line }

Thanks for any help

Upvotes: 2

Views: 228

Answers (1)

Loïc MICHEL
Loïc MICHEL

Reputation: 26150

You just have to escape the special chars from your patterns, here is an easy way:

$666 |% {select-string content.txt -pattern ([RegEx]::Escape($_)) }

Upvotes: 2

Related Questions