Reputation: 159
Here is my sample string.
[echo] The SampleProject solution currently has 85% code coverage.
My desired output should be.
The SampleProject solution currently has 85% code coverage.
Btw, I had this out because I'm getting through the logs in my CI using Jenkins.
Any help? Thanks..
Upvotes: 3
Views: 3838
Reputation: 11
Using below will remove prefix [echo] from all of your logs ,
${BUILD_LOG_REGEX, regex="^\[echo] (.*)$", maxMatches=0, showTruncatedLines=false, substText="$1"}
Upvotes: 1
Reputation: 8552
You can try substText
parameter in BUILD_LOG_REGEX
token to substitute the text matching your regex
New optional arg: ${BUILD_LOG_REGEX, regex, linesBefore, linesAfter, maxMatches, showTruncatedLines, substText} which allows substituting text for the matched regex. This is particularly useful when the text contains references to capture groups (i.e. $1, $2, etc.)
Upvotes: 5
Reputation: 223123
Andrew has the right idea, but with Perl-style regex syntaxes (which includes Java's built-in regex engine), you can do even better:
str.replaceAll("\\[.*?\\]", "");
(i.e., use the matching expression \[.*?\]
. The ?
specifies minimal match: so it will finish matching upon the first ]
found.)
Upvotes: -2
Reputation: 32586
\[[^\]]*\]
will match the bit you want to remove. Just use a string replace function to replace that bit with an empty string.
Upvotes: 0