Powershell - print only text between quotes?

后端 未结 3 1893
孤城傲影
孤城傲影 2021-01-21 17:45

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         


        
3条回答
  •  悲哀的现实
    2021-01-21 18:16

    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]}
    

提交回复
热议问题