MatchesXsYearMonthDuration🔗

Type: Pattern verification
Check that text conforms to the pattern of an xs:yearMonthDuration.
text🔗
Text to be checked
Return🔗
True if the text conforms to the pattern

Code

year_month_duration_rep = r"-?P((([0-9]+Y)([0-9]+M)?)|([0-9]+M))"

pattern = f"^{year_month_duration_rep}$"
return match(pattern, text) is not None