Home > front end >  Regex with negative lookahead, across multiple lines
Regex with negative lookahead, across multiple lines

Time:07-06

I am having trouble getting the proper regex for my current task. I would need all CURDEPTH(0) values ​​without SYSTEM.SOMETHING before them.

I try this demo:

(?:(?!SYSTEM)[\s\S])*?CURDEPTH\(\d \)

Example:

    5724-H72 (C) Copyright IBM Corp. 1994, 2021.
Starting MQSC for queue manager QM.NAME


     1 : DISPLAY QL(*) CURDEPTH
AMQ8409I: Display Queue details.
   QUEUE(DLQ)                              TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(VALUE)       TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SOME.OTHER.VALUE)    TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(VALUABLE_VALUE)            TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(ANOTHER_VALUE)         TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(LAST.VALUE)                        TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(CENSORED_VALUE)      TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(QM.TEST)                       TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.ACCOUNTING.QUEUE)    TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.ACTIVITY.QUEUE)      TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.CHANNEL.EVENT)       TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.COMMAND.EVENT)       TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.COMMAND.QUEUE)       TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.CONFIG.EVENT)        TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.LOGGER.EVENT)        TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.PERFM.EVENT)         TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.PUBSUB.EVENT)        TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.QMGR.EVENT)          TYPE(QLOCAL)
   CURDEPTH(1)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.STATISTICS.QUEUE)    TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.TRACE.ACTIVITY.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.ADMIN.TRACE.ROUTE.QUEUE)   TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.AMQP.COMMAND.QUEUE)        TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.AUTH.DATA.QUEUE)           TYPE(QLOCAL)
   CURDEPTH(117)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.BROKER.ADMIN.STREAM)       TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.BROKER.CONTROL.QUEUE)      TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.BROKER.DEFAULT.STREAM)     TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.BROKER.INTER.BROKER.COMMUNICATIONS)
   TYPE(QLOCAL)                            CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.CHANNEL.INITQ)             TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.CHANNEL.SYNCQ)             TYPE(QLOCAL)
   CURDEPTH(2)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.CHLAUTH.DATA.QUEUE)        TYPE(QLOCAL)
   CURDEPTH(3)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.CICS.INITIATION.QUEUE)     TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.CLUSTER.COMMAND.QUEUE)     TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.CLUSTER.HISTORY.QUEUE)     TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.CLUSTER.REPOSITORY.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(2)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.CLUSTER.TRANSMIT.QUEUE)    TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.DDELAY.LOCAL.QUEUE)        TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.DEAD.LETTER.QUEUE)         TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.DEFAULT.INITIATION.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.DEFAULT.LOCAL.QUEUE)       TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.DOTNET.XARECOVERY.QUEUE)   TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.DURABLE.SUBSCRIBER.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(1)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.HIERARCHY.STATE)           TYPE(QLOCAL)
   CURDEPTH(2)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.INTER.QMGR.CONTROL)        TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.INTER.QMGR.FANREQ)         TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.INTER.QMGR.PUBS)           TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.INTERNAL.REPLY.QUEUE)      TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.INTERNAL.REQUEST.QUEUE)    TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.PENDING.DATA.QUEUE)        TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.PROTECTION.ERROR.QUEUE)    TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.PROTECTION.POLICY.QUEUE)   TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.REST.REPLY.QUEUE)          TYPE(QLOCAL)
   CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.RETAINED.PUB.QUEUE)        TYPE(QLOCAL)
   CURDEPTH(50)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.SELECTION.EVALUATION.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(SYSTEM.SELECTION.VALIDATION.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(0)
AMQ8409I: Display Queue details.
   QUEUE(VEN_IG_REPLY)                     TYPE(QLOCAL)
   CURDEPTH(0)
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.

CodePudding user response:

If a quantifier in a lookbehind assertion is supported, you might check that the previous line does not contain SYSTEM. and then match CURDEPTH(digits)

(?<!^.*\bSYSTEM\..*\n.*)CURDEPTH\(\d \)

Regex demo


Another option is for example to make the pattern more specific, and to use a capture group.

You can start the match with a specific pattern, and then followed matching all lines that do not start with the specific match and the thing that you want to match.

At the end of the pattern, capture what should be in your match.

^AMQ\d.*(?:\n(?!AMQ\d|.*?\bSYSTEM\.).*)*\n\s*(CURDEPTH\(\d \))

Regex demo

  • Related