我有一个很大的文本文件,其中包含括号内的单引号字符串。正则表达式分割成部分然后匹配字符串
[
'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