使用 Regex Powershell 获取第一个 = 之后的所有匹配项以及所有不带 = 的匹配项

问题描述 投票:0回答:1

使用 Windows Powershell 正则表达式,我想在每一行中获取第一个 = 排除后的所有匹配项,即使还有其他 =。 但是,它还应该包含那些不以 = 开头的行,并且应该从行首到行尾。

我从中检索匹配项的代码示例:

ErrorMoving=You cannot=another.
ErrorTooMuchActions
=Too many changes=.{k}=12=aa
WorldErrorWait=An error has occurred.

我想要达到的结果:

You cannot=another.
ErrorTooMuchActions
Too many changes=.{k}=12=aa
An error has occurred.

我尝试做的事情:

(?<=\+?=).*

结果不正确:

You cannot=another.

Too many changes=.{k}=12=aa
An error has occurred.
regex powershell match
1个回答
0
投票

也许

(?m)^.*?=
可以适合您的用例:

@'
ErrorMoving=You cannot=another.
ErrorTooMuchActions
=Too many changes=.{k}=12=aa
WorldErrorWait=An error has occurred.
'@ -replace '(?m)^.*?='

结果:

You cannot=another.
ErrorTooMuchActions
Too many changes=.{k}=12=aa
An error has occurred.

请参阅 https://regex101.com/r/2FfIou/1 了解正则表达式详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.