Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Powershell using regular expressions with array variables.

$
0
0

I've been trying to use regular expression in a PowerShell
script in tandem with arrays so that if I call the value $Array[0] how would I
include the regex modifier to make it end of line. or really any regex values.

foreach-object {$_ -replace $array[0], "Change"}

 


foreach-object {$_ -replace $array[0]$, "Change"}


foreach-object {$_ -replace $array[0]"$", "Change"}


foreach-object {$_ -replace "$array[0]$", "Change"}


$array[0]"$" "$array[0]$"
all error out. It just doesn't know what to do with the "$". The only way I've got this working is with explicit strings
instead of an array I have "123$" but obviously this is not very
conducive to a dynamic script.


foreach-object {$_ -replace "123$", "Change"}


Viewing all articles
Browse latest Browse all 15370

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>