我有內容的文件看起來像這樣:分割文件內容分組由頭
[Something1Something2]
- Interesting data 1
- Interesting data 2
[Something3]
- Interesting data 1
- Interesting data 2
[Something4]
- Interesting data 1
- Interesting data 2
我想用灑或其他一些我未知的命令來獲得部分恢復,然後我可以指數像這樣:
$myStringArray[0]
prints:
- Interesting data 1
- Interesting data 2
我曾嘗試通過使用正則表達式,但沒有運氣來實現這一目標:
"[Somthing1] somedata1 [Something2] somedate2" -split "\[(.*)\]"
我意識到,這是不是多線如上所述,但原則是相同的,只爲測試。
如果我這樣做上述文件,嘗試一下用多線:
$myfile = Get-Content .\test.txt
($myfile -split "\[.*\]")
我得到的14個,而不是3項的數組。
有多單線路匹配之間的正則表達式的差異。 – Nick