捕获重复基团,由可选和/或]隔开>

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

这是我正在努力的通用模式

如果condition1和|或condition2

然后action1和|或action2

条件和动作通常具有以下模式:situation >= 10 or situationB = off|on

问题是重复的和/或处于状态/动作中,可能完全不存在(0个计数为和/或)或多个(*)。

示例字符串:situation >= 10 or situationB = off and situationC = onsituation = on

我尝试过但需要一些帮助:

^\s*(\w+)\s*(=|\>=)\s*(\d+|\w+)\s*(and|or)?

regex101 link

如何修改正则表达式,以便可以将可能和/或可能不分隔和/或不分隔的每个条件/动作归为一组?

如果条件1和|或条件2然后动作1和|或动作2,条件和动作通常都具有这种模式:[>> 10或...

regex regex-lookarounds regex-group
2个回答
0
投票

您可以尝试使用以下正则表达式模式:


0
投票

您可以使用\G锚点在上一场比赛之后继续。

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