I’m trying to see if there is an entry for some input in a file, so I’m using a regular expression to query each line:
cat $file | where {$_ -match “^script\$fileName -*”}
where $fileName is some input defined elsewhere.
How do I alter the regex to interpolate the variable instead of matching for ‘$fileName’ ?
In addition to the answer given, as $fileName could contain characters such as ‘.’ or ‘\’ you should escape it as follows:
The Escape method will escape bits like ‘.’ and ‘\’ for you.
E.g.
gives