Advertisement
bl00dt3ars

2

Aug 15th, 2021
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. import re
  2.  
  3. pattern = r'(?P<first_sep>!)(?P<command>[A-Z][a-z]{2,})(?P=first_sep):\[(?P<message>[a-zA-Z]{8,})\]'
  4. n = int(input())
  5.  
  6. for _ in range(n):
  7.     text = input()
  8.     matches = list(re.finditer(pattern, text))
  9.     if len(matches) > 0:
  10.         for el in matches:
  11.             nums = []
  12.             for char in el.group('message'):
  13.                 nums.append(str(ord(char)))
  14.             text_to_print = el.group("command")+': '+' '.join(nums)
  15.             print(text_to_print)
  16.     else:
  17.         print(f'The message is invalid')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement