MatchesXsBase64Binary🔗

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

Code

b04_char = "[AQgw]"
b04 = f"{b04_char}\\x20?"

# Base64 characters whose bit-string value ends in '00'
b16_char = "[AEIMQUYcgkosw048]"
b16 = f"{b16_char}\\x20?"

b64_char = "[A-Za-z0-9+/]"
b64 = f"{b64_char}\\x20?"

b64quad = f"({b64}{b64}{b64}{b64})"

# b64_final_quad represents three octets of binary data without trailing space.
b64_final_quad = f"({b64}{b64}{b64}{b64_char})"

# padded_8 represents a single octet at the end of the data.
padded_8 = f"{b64}{b04}=\x20?="

# padded_16 represents a two-octet at the end of the data.
padded_16 = f"{b64}{b64}{b16}="

b64final = f"({b64_final_quad}|{padded_16}|{padded_8})"

base64_binary = f"({b64quad}*{b64final})?"

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