I have a variable $s that holds a filepath and an error based on piping a get-childitem to selecting a pattern in a string. the output looks something like this:
C:\Users\admin\Desktop\testpoint.txt:15906: Error: an error has been logged.
where
$s = C:\Users\admin\Desktop\testpoint.txt:15906: Error: an error has been logged.
Now what I want to do is select the string between \ and .txt (IE, the output in this example is testpoint) and output it as a secondary variable. 'regex::Matches' is what will allow me to do this from what I have researched, but the syntax is what is killing me. so far this is what i attempted:
[regex]::Matches($s, '\([^/)]+).txt')
but, it errors out. How do I go about getting whatever is between two constraints, in this case the constraints being the character " \ " and the string ".txt?"
Get-ChildItem ... |Select-String -Pattern $pattern |ForEach-Object { (Get-Item -LiteralPath $_.Path).BaseName }would have given you just the matched file's name sans the extension