Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell - print only text between quotes?

Tags:

powershell

How can I have the output of the following text only show the text in the quotes (without the quotes)?

Sample text"

this is an "apple". it is red
this is an "orange". it is orange
this is an "blood orange". it is reddish

becomes:

apple
orange
blood orange

Ideally I'd like to do it in a one liner if possible. I think it's regular expression with -match but I'm not sure.

like image 965
Mike J Avatar asked Oct 27 '25 07:10

Mike J


2 Answers

here is one way

$text='this is an "apple". it is red
this is an "orange". it is orange
this is an "blood orange". it is reddish'

$text.split("`n")|%{
$_.split('"')[1]
}

This is the winning solution

$text='this is an "apple". it is red
this is an "orange". it is orange
this is an "blood orange". it is reddish'

$text|%{$_.split('"')[1]}
like image 199
Loïc MICHEL Avatar answered Oct 29 '25 06:10

Loïc MICHEL


Just another way using regex:

appcmd list apppool | % { [regex]::match( $_ , '(?<=")(.+)(?=")' ) } | select -expa value

or

 appcmd list apppool | % { ([regex]::match( $_ , '(?<=")(.+)(?=")' )).value }
like image 21
CB. Avatar answered Oct 29 '25 07:10

CB.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!