I have a Jenkins build that copies an artifact from another build.
Using description setter plugin I want to extract the build number from which I take the artifact.
The log file contains this line :
Copied 1 artifact from "Mybuild" build number 569
I need to use regex to extract only the integer 569 (can be any int). Also the 1 can be any int and Mybuild can be any string (but no spaces, one word). I can assume the words Copied, artifact, from, build, number are constant and always appear
I have tried to match a regex, but with no luck. Also tried some regex generator websites but no luck either.
Thanks.
You could probably use
and then use the third group (or remove the parentheses around the first two captured tokens and use group number 1).
\drefers to any decimal digit, the+trailing it is a so-called quantifier that will try matching the previous token (the digit in this case) at least one times and as often as possible.[^"]is a character class containing any character that is not a double quote. This way we can make sure that we catch everything within the quotes (not strictly necessary here, but a good pattern to keep in mind). All the rest is just matched verbatim.Quick PowerShell test: