I have the following PowerShell script:
$SCRIPTNAME = "myfile.js"
$SUBJECT = Get-Content $SCRIPTNAME | Out-String
if ($SUBJECT -match ".*/// COMMENT.*?$(.*)")
{
echo $matches[1];
}
$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
It is generating the following error (I'm trying to use regex capture groups, but its not working):
.* : The term '.*' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\User\Desktop\install.ps1:21 char:39
+ if ($SUBJECT -match ".*/// COMMENT.*?$(.*)")
+ ~~
+ CategoryInfo : ObjectNotFound: (.*:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Why is it having issues with the .* part of the second capture group?
$in front of it which might be causing problems. Either escape it if you want a literal$or move it to the end of the pattern.\$instead, but this still produces the same error.$(.*)which would also cause an error. Using single quotes on the entire string would fix that. If you are still having an issue showing us some sample data and desired output would help the Community address your issue.(?<Text>.*). Then you will have$matches.Text