I've searched online and found some solutions, but none of them work.
In python, all you have to do is import re
From the documentation, in GDScript it looks like you do this:
var regex = RegEx.new()
regex.compile("\\w-(\\d+)")
But it's not working.
Specifically, this is the code (in python) that I want to use:
def getAgeRange(text):
minString = text.split("-")[0].strip()
maxString = text.split("-")[1].strip()
match = re.match(r"([0-9]+)[\s+]?([a-z]+)", maxString)
matchList = match.groups()
max = matchList[0]
max_units = matchList[1]
match = re.match(r"([0-9]+)\s+([a-z]+)", minString)
if match:
matchList = match.groups()
min = matchList[0]
min_units = matchList[1]
else:
min = minString
min_units = max_units
print(str(min) + str(min_units) + "-" + str(max) + str(max_units))
An example of strings I would use would be 3-5 wks
and 3 mo-6yo