我正在努力解决我无法弄清楚的正则表达式:
我的字符串是这样的
Y
[sudo] Password for user: Other Text here
even more text here: with more text
Run Code Online (Sandbox Code Playgroud)
我的目标是选择从第一行到第一个“:”的所有文本,并将其替换为任何内容。
问题是前两行可能存在也可能不存在,并且仍然必须选择直到并包括第一次出现“:”的文本
我的最终结果应该是这样的:
Other Text here
even more text here: with more text
Run Code Online (Sandbox Code Playgroud)
这就是我得到的,但现在我被困住了:
$Test[0..3] -replace ('[a-zA-Z]+\w\:*\s')
Run Code Online (Sandbox Code Playgroud)
但这留下了第 0 行和第 1 行,并且也没有摆脱 [sudo] :(
希望正则表达式专家能给我一些见解:)
编辑 有关实际字符串的更多信息(非常长并且包含 unix 日志文件):
C:\> $MainArray
y
[sudo] password for User: 1485673353 1 33412 2 appxxx 1801152 1801047 0 appxxx bptm image copy is not ready, retry attempt: 6 of 500 o
bject is busy, cannot be closed …Run Code Online (Sandbox Code Playgroud)