Import additional classes into groovy

Some packages that exist in Java, do not exist in groovy. If you want to use these packages you will need to import them.

For example, Groovy doesn’t have a regex package, if you want to use regex you need to import it as shown:

Example of importing and using regex class

import java.util.regex.Pattern;//imports regex pattern class def pattern = Pattern.compile("test: [a-z]+") assert pattern.class == Pattern; print('pattern class: '+pattern.class); def matcher = pattern.matcher(subject); if(matcher.find()) { print("matched value: " + matcher.group(1)); //Prints out the matched value result.setValue(matcher.group(1)); //Sets the value to matched Regex }

 

for more information on importing with groovy see the following page: https://groovy-lang.org/structure.html