16 lines
501 B
Python
16 lines
501 B
Python
import re
|
|
|
|
PLACEHOLDER_PATTERN = re.compile(r"\{#(?:var|num)#\}")
|
|
|
|
|
|
def message_matches_template(template_text: str, message: str) -> bool:
|
|
message = message.strip()
|
|
if not message:
|
|
return False
|
|
parts = PLACEHOLDER_PATTERN.split(template_text.strip())
|
|
pattern = ""
|
|
for index, part in enumerate(parts):
|
|
pattern += re.escape(part)
|
|
if index < len(parts) - 1:
|
|
pattern += r".+?"
|
|
return re.fullmatch(pattern, message, flags=re.DOTALL) is not None
|