Reputation: 585
I tried to execute the shell commands and store the output result content to the string variable. From that string variable, i need to find and get whether the required decimal value using regular expression. Below is the code i tried. Job got failed continuously. Could anyone please help me to resolve this?
My output should be like "5.2.0".
node("10.6")
{
stage 'test'
try
{
def matcher = "5.2.0.123" =~ /^[0-9]+(\.[0-9]+)?(\.[0-9]+)?/
if( matcher.matches() ) { echo "success"}
}
catch(Exception e)
{ echo e
}
}
Upvotes: 0
Views: 6680
Reputation: 1367
In your statement true, use findAll
method to return the output from regex, like this:
"5.2.0.123".findAll(/^[0-9]+(\.[0-9]+)?(\.[0-9]+)?/)[0]
Upvotes: 1