Extract a substring using PowerShell

前端 未结 8 999
灰色年华
灰色年华 2020-12-07 22:43

How can I extract a substring using PowerShell?

I have this string ...

\"-----start-------Hello World------end-------\"

I have to e

8条回答
  •  情书的邮戳
    2020-12-07 22:56

    The -match operator tests a regex, combine it with the magic variable $matches to get your result

    PS C:\> $x = "----start----Hello World----end----"
    PS C:\> $x -match "----start----(?.*)----end----"
    True
    PS C:\> $matches['content']
    Hello World
    

    Whenever in doubt about regex-y things, check out this site: http://www.regular-expressions.info

提交回复
热议问题