0

I've following text which spans across lines and which I want to match using regular expression -

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project RuleEngineImpl: Compilation failure: Compilation failure: 
[ERROR] /C:/Jenkins/workspace/RedmineAndReviewboardProject/SVNCheckout/Source/RuleEngineManagement/RuleEngineImpl/src/main/java/com/ruleengine/impl/manager/RuleManagerImpl.java:[26,58] package com.test.ruleengine.api.persistence does not exist
[ERROR] /C:/Jenkins/workspace/RedmineAndReviewboardProject/SVNCheckout/RuleEngineManagement/RuleEngineImpl/src/main/java/com/test/test/ruleengine/impl/manager/RuleManagerImpl.java:[41,17] cannot find symbol
[ERROR]   symbol:   class RulePersistanceManager
[ERROR]   location: class com.ruleengine.impl.manager.RuleManagerImpl
[ERROR] /C:/Jenkins/workspace/RedmineAndReviewboardProject/SVNCheckout/test/Source/RuleEngineManagement/RuleEngineImpl/src/main/java/com/test/test/ruleengine/impl/manager/RuleManagerImpl.java:[55,47] cannot find symbol
[ERROR]   symbol:   class IRulePersistance
[ERROR]   location: class com.test.ruleengine.impl.manager.RuleManagerImpl
[ERROR] /C:/Jenkins/workspace/RedmineAndReviewboardProject/SVNCheckout/test/Source/RuleEngineManagement/RuleEngineImpl/src/main/java/com/test/test/ruleengine/impl/manager/RuleManagerImpl.java:[61,33] cannot find symbol
[ERROR]   symbol:   class IRulePersistance
[ERROR]   location: class com.test.ruleengine.impl.manager.RuleManagerImpl
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

To match this, I wrote following regex but it is not able to find entire path -

^\[ERROR\] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin((.|\n)*)\[ERROR\] To see the full stack trace of the errors, re-run Maven with the -e switch.*

Could you please suggest regular expression which will help to match lengthy text which is spanned across lines?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Alpha
  • 13,320
  • 27
  • 96
  • 163
  • 2
    What tool are you using? `sed`, `awk`, `grep`? Note Linux tools are mostly line based and common NFA regex recipes do not work there. – Wiktor Stribiżew Nov 14 '19 at 10:07
  • I'm trying it through Jenkins Build Failure Analyzer plugin - https://wiki.jenkins.io/display/JENKINS/Build+Failure+Analyzer. Not sure what is uses internally. – Alpha Nov 14 '19 at 10:12
  • You should not use `(.|\n)*`, if the engine is NFA use `[\s\S]*?`. And always escape dots that are literal dots. – Wiktor Stribiżew Nov 14 '19 at 10:15
  • @WiktorStribiżew thanks for the answer! But unfortunately it did not work. – Alpha Nov 14 '19 at 10:24
  • Does `.*` itself work? – Wiktor Stribiżew Nov 14 '19 at 10:30
  • No that also did not work. – Alpha Nov 14 '19 at 10:56
  • @WiktorStribiżew, this looks issue with Build Failure Analyzer plugin. Same text with regex having `.*` and other options you suggested, is passing in https://www.freeformatter.com/regex-tester.html. Will check this with Jenkins plugin team. – Alpha Nov 14 '19 at 11:08
  • Just note that `^` will match the start of string. If you need to match start of a line, add `(?m)` at the regex pattern start. – Wiktor Stribiżew Nov 14 '19 at 11:12
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/202330/discussion-between-tdhm-and-wiktor-stribizew). – Alpha Nov 14 '19 at 11:22

1 Answers1

0

You need to use regex along with Sed. Using sed you get the multiline to simple string. and apply grep on that.

Example: Below from bgp-config snippet which is multiline xml block in file.log. And extracting regex expression.

'sed -n \'/<bgp-config /,/<\/bgp-config>/p\' /temp/file.log | grep -Po \'<as>\K(.*)(?=</as)\''