| Running the following Jenkins declarative pipeline job I would expect the output to be the same for each regular expression: Here is the content of the pipeline: pipeline{ agent{ node{ label('master')}} stages{ stage('RegEx'){ steps{ script{ def m_ex def m_in stanza = '''Hello. how are you doing? It is a nice day. Are we there yet?''' m_ex = stanza =~ /(m?).nice./ if (m_ex){ println "Found: ${m_ex[0][0]}" }else { println "m_ex did not return a match. Why?" } if ((m_in = stanza =~ /(m?).nice./)){ println "Found: ${m_in[0][0]}" }else { println "m_in did not return a match. Why?" } println GroovySystem.version } } } } } Here is the result: Running in Durability level: MAX_SURVIVABILITY [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in /var/lib/jenkins/workspace/Test/RegularExpression [Pipeline] { [Pipeline] stage [Pipeline] { (RegEx) [Pipeline] script [Pipeline] { [Pipeline] echo Found: It is a nice day. [Pipeline] echo m_in did not return a match. Why? [Pipeline] echo 2.4.12 [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS |