PowerShell: Split String without removing the split-pattern?

后端 未结 1 1895
青春惊慌失措
青春惊慌失措 2021-01-22 02:02

I tried the solution form here but I get the error (my translation) Regex.Split is unknown??
I need to split the line into an string-array but keeping the begin of the lines

相关标签:
1条回答
  • 2021-01-22 02:27

    Here you go:

    $regex = [regex] '(?=prg=PowerShell°)'
    $splitarray = $regex.Split($subject);
    

    To split, we are using a zero-width match (i.e., we split without losing characters). To do this, we look ahead to see if the next characters are prg=PowerShell° This is what the regex (?=prg=PowerShell°) does.

    0 讨论(0)
提交回复
热议问题