I'm trying to extract the data between a starting and ending markers in a string. There are multiple matches and I need to extract all the matches (into an array or list doesn't matter)
I have a limitation and cannot use Regex Matcher on my setup so as an alternative I'm looking at using string.split()
with a regex.
This pattern works with Regex Matcher and extracts all the matches between the starting and ending marker.
def items = str =~ /(?s)(?<=START:M).*?(?=END:M)/
However, when I try to use the same pattern on string.split
def items = str.split(/(?s)(?<=START:M).*?(?=END:M)/)
it returns the end and start markers themselves for each match instead of what's between them.
e.g. [ "END:M START:M", "END:M START:M", "END:M START:M" ... ]
What am I missing, why isn't the Split pattern returning the same groups as Matcher pattern?
Aucun commentaire:
Enregistrer un commentaire