Groovy regular expressions have a ==~ operator which will determine if your string matches a given regular expression pattern.

Example

// ==~ tests, if String matches the pattern
assert "2009" ==~ /\d+/  // returns TRUE
assert "holla" ==~ /\d+/ // returns FALSE

Using this, you could create a regex matcher for your sample data like so:

// match 'somedata', followed by 0-N instances of ':somedata'...
String regex = /^somedata(:somedata)*$/

// assert matches...
assert "somedata" ==~ regex
assert "somedata:somedata" ==~ regex
assert "somedata:somedata:somedata" ==~ regex

// assert not matches...
assert "somedata:xxxxxx:somedata" !=~ regex
assert "somedata;somedata;somedata" !=~ regex

Read more about it here:

http://docs.groovy-lang.org/latest/html/documentation/#_match_operator

Answer from Nick Grealy on Stack Overflow
🌐
OneCompiler
onecompiler.com › groovy › 3vn2vdadj
Groovy Online Compiler
OneCompiler's Groovy online editor/ console/ playground helps you to write, compile, debug and run Groovy code online
🌐
Regex Tester
regextester.com › 94608
groovy method name regex - Regex Tester/Debugger
Regex Tester is a tool to learn, build, & test Regular Expressions (RegEx / RegExp).
🌐
Regexbuddy
regexbuddy.com › groovy.html
Groovy java.util.regex Regular Expressions
Just tell RegexBuddy what you want to do, and you will get the proper Groovy code straight away. Anything can be done: testing a string for a match, extracting search matches, validating input, search-and-replace, splitting a string, etc.
🌐
Blazemeter
blazemeter.com › blog › groovy-regex
How to Use Groovy RegEx For Testing | Perforce BlazeMeter
In this article, I will show you how to use Groovy RegEx (Regular Expressions) when performance testing an API response with JMeter.
🌐
Regex101
regex101.com › r › mgA9Ri › 1 › debugger
regex101: import regex groovy
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
🌐
UC Davis
web.cs.ucdavis.edu › ~doty › fall2015ecs120 › regex.html
Regex testing information
It is therefore useful to test your regular expressions using a Groovy interpreter, so that you know you are getting the same results we get when we grade homework. Groovy uses Java libraries under the hood, so if you know Java, you can test your regex's in that language as well.
🌐
Baeldung
baeldung.com › home › groovy › pattern matching in strings in groovy
Pattern Matching in Strings in Groovy | Baeldung
March 26, 2025 - Most of the time, and especially when writing tests, we’re not really interested in creating Pattern objects, but instead, want to check if a String matches a certain regular expression (or Pattern). Groovy, therefore, also contains the match operator ==~. It returns a boolean and performs a strict match against the specified regular expression. Basically, it’s a syntactic shortcut over calling Pattern.matches(regex, string).
Find elsewhere
🌐
Appspot
groovyconsole.appspot.com › script › 5077290488692736
Groovy web console - regex test
Groovy web console · regex test · Published 6 years ago by Anonymous · Actions Execute script ▶ Edit in console Back to console Show/hide line numbers View recent scripts · def pattern = "(?<=\/)(\d+)(?=-)" def branchName = "company/feature/1234-abc-xyz" branchName =~ pattern
🌐
Regular-Expressions.info
regular-expressions.info › groovy.html
Using Regular Expressions in Groovy
In Groovy, you can create this instance directly from the literal string with your regular expression using the =~ operator. No space between the = and ~ this time. ... Finally, the ==~ operator is a quick way to test whether a regex can match a string entirely.
🌐
Szymon Stepniak
e.printstacktrace.blog › home › groovy cookbook › groovy regular expressions - the definitive guide (part 1)
Groovy Regular Expressions - The Definitive Guide (Part 1)
May 8, 2020 - When you get the java.util.regex.Matcher object, you can essentially use any of its standard methods, or you can continue reading to learn more Groovy way to do it.
🌐
CodinGame
codingame.com › playgrounds › 30433 › groovy-regex
Groovy Regex
CodinGame is a challenge-based training platform for programmers where you can play with the hottest programming topics. Solve games, code AI bots, learn from your peers, have fun.
🌐
Regex101
regex101.com
regex101: build, test, and debug regex
Online regex tester and debugger with real-time match highlighting, detailed explanations, substitutions, unit tests, benchmarking, and code generation. Supports PCRE2, JavaScript, Python, Go, Java, .NET, Rust, POSIX ERE, and POSIX BRE.
🌐
CodeProject
codeproject.com › Questions › 5329882 › Groovy-regex-or-pattern-making
[Solved] groovy regex or pattern making
April 16, 2022 - Disclaimer: References to any specific company, product or services on this Site are not controlled by GoDaddy.com LLC and do not constitute or imply its association with or endorsement of third party advertisers
🌐
Java Code Geeks
examples.javacodegeeks.com › home › jvm languages › groovy
Groovy Regex Example - Java Code Geeks
March 29, 2019 - You can see that the pattern class name is java.util.regex.Pattern. In order to test whether if provided string matches with the pattern, you can use following. ... package com.javacodegeeks.groovy.regex class GroovyRegexMatch { static main(args) { def nameRegex = ~'john' println nameRegex.matcher("john").matches() // true def ipAddressRegex = ~/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ println ipAddressRegex.matcher("127.0.0.1").matches() // true } }
🌐
GitHub
github.com › quickhack › playground › blob › master › groovy › src › main › java › com › oldratlee › groovy › regex › RegEx.groovy
playground/groovy/src/main/java/com/oldratlee/groovy/regex/RegEx.groovy at master · quickhack/playground
package com.oldratlee.groovy.regex · · import java.util.regex.Matcher · import java.util.regex.Pattern · · · // ~ creates a Pattern from String · def pattern = ~/foo/ assert pattern instanceof Pattern · assert pattern.matcher("foo").matches() // returns TRUE ·
Author: quickhack
🌐
DEV Community
dev.to › awwsmm › the-power-of-regular-expressions-30in
The Power of Regular Expressions - DEV Community
October 8, 2018 - Remember that nothing in life is simple, so there are lots of different regex variations (or "flavors"), with support for different features. I'll try to stick to things which are common to all flavors, but I'll make a note of when that's not the case. A regular expression is a sequence of characters which defines a pattern. That pattern can be searched for within other character sequences (or strings). A regular expression can be as simple as · groovy:000> stringToSearch = "A string that contains the letter 'z'." ===> A string that contains the letter 'z'. groovy:000> thingToFind = stringToSearch =~ /z/ ===> java.util.regex.Matcher[pattern=z region=0,38 lastmatch=] groovy:000> thingToFind.find() ===> true groovy:000> thingToFind.start() ===> 35 groovy:000> stringToSearch[35] ===> z