我有一個很大的文本文件,其中包含括號內的單引號字符串。正則表達式分割成部分然後匹配字符串
[
'stringIneedToExtractBetweenSingleQuotes' some other
text
and
characters asdasf/*- 'AnotherStringIneedToExtract'
]
[
'anotherstring' some other
text and characters asdasfds/*- 'PleaseExtractMe'
]
[...]
我想獲得引號之間的字符串由括號分隔,像數組索引分離的部分,
$array[0]
或$matches[0]
stringIneedToExtractBetweenSingleQuotes
AnotherStringIneedToExtract
$array[1]
或$matches[1]
anotherstring
PleaseExtractMe
使用'(.*?)'
我可以提取所有單引號之間的字符串,但我不知道哪一個很有意義的使用:
使用PowerShell
.split(']')
方法分裂文成數組,然後使用'(.*?)'
提取字符串。最好的方法(如果可能的話),使用正則表達式提取這些字符串,並使用[]作爲分隔符分割成部分。
我不認爲你需要拆分字符串,只需使用捕獲組運行正則表達式後。 https://mcpmag.com/articles/2015/09/30/regex-groups-with-powershell.aspx –
_pretty大文本文件_是主觀的。你能用數字或者行或者平均文件大小來量化嗎? – Matt
文件中是否有任何單引號字符串_outside_括號?還是確實不需要考慮括號的存在? – Matt