kaz
kaz

Reputation: 35

Extract text from a string using Powershell

I have a URL from which I need to extract a text. The URL is of the form:

abcd.com/File1/00012121
abcd.com/File12/00012121
abcd.com/File123/00012121

I need to extract File1, File12 and File123 respectively.

Upvotes: 0

Views: 187

Answers (2)

restless1987
restless1987

Reputation: 1598

try

$URL -replace '.+\/(\w+)' , '$1'

Upvotes: 0

DarkLite1
DarkLite1

Reputation: 14695

You could try something like this:

('abcd.com/File1/00012121' -split '/')[1]

Or:

'bcd.com/File1/00012121' -split '/' | Select -First 1 -Skip 1

Upvotes: 1

Related Questions