Velocity: Regex capturing groups
I was wondering if there's a possibility in velocity to use regex capturing groups? So, as a simple example, we may want to get "Some Name", "13:00" and "14:00" from the following input string: "Some Name: 13:00 - 14:00".
There are multiple ways how this can be achieved but one possibility would be to use a simple regex such as "^(.+):\s?(\d{1,2}:\d{1,2})\s?\-\s?(\d{1,2}:\d{1,2})$" and then extract the parts from the three capturing groups.
Something like "matches" in Velocity only returns a Boolean which can be used to e.g. compare a input to a pattern.
#set( $input = "Some Name: 13:00 - 14:00" )
#set( $regex = "^(.+):\s?(\d{1,2}:\d{1,2})\s?\-\s?(\d{1,2}:\d{1,2})$" )
#if ( $input.matches($regex) )
## We have a match
#end
In JavaScript land you could e.g. do something simple such as
const [_, name, timeFrom, timeTo] = "Some Name: 13:00 - 14:00".match(/^(.+):\s?(\d{1,2}:\d{1,2})\s?\-\s?(\d{1,2}:\d{1,2})$/i) || [];
Is there something similar in Velocity? Given the example above, we could "split" by multiple delimiters or use multiple "replace" runs to get the parts but that obviously has its limitations and feels somewhat hacky.
Maybe @sanfordwhiteman has an idea? Thanks in advance.