extract substring using regex in groovy

The code below shows the substring extraction using regex in groovy:

class StringHelper {
@NonCPS
static String stripSshPrefix(String gitUrl){
    def match = (gitUrl =~ /ssh:\/\/(.+)/)
    if (match.find()) {
        return match.group(1)
    }
    return gitUrl
  }
static void main(String... args) {
    def gitUrl = "ssh://[email protected]:jiahut/boot.git"
    def gitUrl2 = "[email protected]:jiahut/boot.git"
    println(stripSshPrefix(gitUrl))
    println(stripSshPrefix(gitUrl2))
  }
}

Try:

def result = (articleContent =~ /<!\[CDATA\[(.+)]]>/)[ 0 ]​[ 1 ]

However I worry that you are planning to parse xml with regular expressions. If this cdata is part of a larger valid xml document, better to use an xml parser