MatchesXsDuration🔗

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

Code

durationRep = (
    '-?P((([0-9]+Y([0-9]+M)?([0-9]+D)?|([0-9]+M)([0-9]+D)?|([0-9]+D))(T(([0-9]+H)([0-9]+M)?([0-9]+(\\.[0-9]+)?S)?|([0-9]+M)([0-9]+(\\.[0-9]+)?S)?|([0-9]+(\\.[0-9]+)?S)))?)|(T(([0-9]+H)([0-9]+M)?([0-9]+(\\.[0-9]+)?S)?|([0-9]+M)([0-9]+(\\.[0-9]+)?S)?|([0-9]+(\\.[0-9]+)?S))))'
)
pattern = (
    f'^{durationRep}$'
)
return match(
    pattern,
    text
) is not None