简体   繁体   中英

would like to get a regex expression for my multi line log

I am trying to form the correct regex to capture strings out of a multi line log like -

AMQ9206: Error sending data to host hic4 (10.254.101.168)(1414).

or

AMQ9999: Channel 'TO.MQH4' to host 'HIC4(1414)' ended abnormally.

multi line log excrepts as follows -

06/17/16 22:45:14 - Process(509640.1) User(mqsystem) Program(runmqchl)
                    Host(mqah103p) Installation(MQAppliance)
                    VRMF(8.0.0.4) QMgr(PRDCDE3A)

AMQ9206: Error sending data to host hic4 (10.254.101.168)(1414).

--------------------------- amqccita.c : 3166 ----------------------------------

06/17/16 22:45:14 - Process(509640.1) User(mqsystem) Program(runmqchl)
                    Host(mqah103p) Installation(MQAppliance)
                    VRMF(8.0.0.4) QMgr(PRDCDE3A)

AMQ9999: Channel 'TO.MQH4' to host 'HIC4(1414)' ended abnormally.

Depending on the programming language, this will be expressed slightly differently, but the main trick is to enable multi-line mode in your regex. This will allow special characters like ^ and $ to match the beginning and end of a line instead of the beginning and end of the string.

Assuming your log always has this general format of AMQ followed by 4 numbers, the regex would be something like:

/^AMQ\d{4}: .*$/gm

Regex101 Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM