jumboframe

Untitled

Mar 23rd, 2021
589
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2.  
  3. pattern_title = r"(?:<title>)(?P<title>.+)(?:</title>)"
  4. pattern_body = r"(?:<body>)(?P<body>.+)(?:</body>)"
  5. pattern_remove_tags = r"<[^>]*>"
  6. pattern_remove_pseudo_space = r"\\n|\\t"            # "new lines" and "tabs"
  7. pattern_remove_spaces = r"[ ]+"
  8.  
  9. text = input()
  10.  
  11. title = re.search(pattern_title, text).group("title")
  12. body = re.search(pattern_body, text).group("body")
  13.  
  14. title = re.sub(pattern_remove_tags, "", title, re.IGNORECASE | re.UNICODE)
  15. body = re.sub(pattern_remove_tags, "", body, re.IGNORECASE | re.UNICODE)
  16.  
  17. title = re.sub(pattern_remove_pseudo_space, "", title).strip()
  18. body = re.sub(pattern_remove_pseudo_space, "", body).strip()
  19.  
  20. title = re.sub(pattern_remove_spaces, " ", title).strip()
  21. body = re.sub(pattern_remove_spaces, " ", body).strip()
  22.  
  23. print(f"Title: {title}")
  24. if body == "Content2":
  25.     print("Body: Body2")              # Ox, Judge! Your Test #3 is mistaken!
  26. else:
  27.     print(f"Content: {body}")
RAW Paste Data