I am trying to generate a regex string that I can't seem to get right.
I want to match any lines containing -AS-
AND -CO
while excluding -DC-
CCO-AS-02-CO
EKY-2F-AS-02-CO
LKS-AS-06-CO
LKS-AS-DC-07
LKS-AS-52-CR
ATX-A2-DC-AS-08-CO
BAL-0F-AS-06-CO
BAL-2F-AS-03-CO
CNC-1F-AS-05-CO
I'm not familiar with how to perform and but know that the this works for the containing chunks: (.*AS.*CO)
Help?
答案 0 :(得分:2)
答案 1 :(得分:1)
你可以用纯粹的前瞻来做这件事:
^(?=.*-AS-)(?=.*-CO)(?!.*-DC-).*$
^^ a line with:
^^^ do not have -DC- in the line
^^^ do have -CO
^^^ do have -AS-
^ Anchor, start of line
这三个术语可以在线上以任何顺序排列。
答案 2 :(得分:0)
If the AS
and CO
could be out of order, this could detect their presence.
^(?!.*-DC(?=-|$))(?=.*-AS(?=-|$))(?=.*-CO(?=-|$)).+$