giving string without first two or three letter in power shell


i want to read a string from a line. The line is

 ERROR: file'C:\Program Files (x86)\movies\action\Theincrediblehulk.mp3' is missing

I want only


the code i use to get only that string is

Select-String tt.txt -pattern [regex]"[A-Za-z]+\.mp3" -AllMatches | % { $_.Matches } | % { $_.Value }

but it is giving me the output as


first two or three words is missing. Please suggest a better way to solve this. i use [A-Za-z] because name is dynamic.


Mathias R. Jessen's answer is a better solution, however this answer explains why the original code isn't working as expected.

I assume by your [regex] at the beginning, you're trying to tell powershell to convert your string to a regex object. However powershell is actually interpreting your argument as

-pattern '[regex]"[A-Za-z]+\.mp3"'

If you do want to explicitly treat your string as a regex object, you'll need to wrap the value in parentheses

-pattern ([regex]"[A-Za-z]+\.mp3")

Although the regex cast is not necessary, so the string alone is sufficient.

-pattern '[A-Za-z]+\.mp3'
By : Alex

Start by grabbing everything in between the quotes:

$Filepaths = Select-String tt.txt -pattern "'([^']+)'" -AllMatches | % { $_.Matches } | % { $_.Groups[1].Value }

Now you can use either Split-Path -Leaf to grab the file name:

$Filenames = $Filepaths |Split-Path -Leaf

or Path.GetFileName():

$Filenames = $Filepaths |% { [System.IO.Path]::GetFileName($_) }

Disable attribute only associates button and input filelds, the thing you want to do here is , event.preventDefault . It will work like disable, but it will depend upon your coding, if you want to show it disabled, you have to add add via jquery

This video can help you solving your question :)
By: admin