user6348718
user6348718

Reputation: 1395

Java regex in Jenkins Text Finder to match 2 lines

I have 2 lines in my jenkins console output and I am trying to capture them using the Jenkins Text Finder plugin using java regex My console output looks something like this:

**The total percentage is:70%
Student passed the exam**

The java regex I tried is:

The total percentage is:([0-9]\d|\d{3,})%(\n|$)Student passed the exam

In the place of (\n|$) to pickup the next new line I tried [\s\S] and (.|\n). But nothing is working. Can someone help me with this.

EDIT: The build should be unstable when either one of them is found or when both the lines were found. Meaning for A|B|AB

Upvotes: 1

Views: 3680

Answers (3)

Mohammad Yusuf
Mohammad Yusuf

Reputation: 17074

Try this:

T.*?:(\d+)%\s+.*?m

Demo: https://regex101.com/r/1jtHP4/1

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522635

I think you can get away with the following regex:

^The total percentage is:[0-9]{1,2}(\.[0-9]{1,})?%|Student passed the exam$

Since the presence of either sentence represents a match in your console output, therefore you don't need to check for both. So a regex with an alternation is possible here.

Here is an explanation of the pattern matching the percentage:

[0-9]{1,2}     one or two leading digits
(
    \.         followed by an (optional) decimal point
    [0-9]{1,}  followed by one or more digits after that (again optional)
)?
%              followed by a percent sign

Demo here:

Regex101

Upvotes: 1

Amey Shirke
Amey Shirke

Reputation: 734

Try this:

/The total percentage is:([0-9]\d|\d{3,})%\W+Student passed the exam/igm

i : for ignoring the case

g: matching globally

m: for multiline matching

Upvotes: 0

Related Questions