I have this long regex in the code bellow
import re
message = "/sell 2000 USDT @ 5.56 111.222.333-44 user@example.com"
regex = re.compile(r"^/(?P<operation>\w+) (?P<amount>.+) (?P<network>.+) @ (?P<rate>.+) (?P<legal>.+) (?P<contact>.+)")
result = regex.match(message)
print(result.groupdict())
I want know if it is possible to break each group in one line, to make more readable. Unfortunately my input data is on a single line, is it possible?
>Solution :
Just split it up with quotes
regex = re.compile(r"^/(?P<operation>\w+)"
" (?P<amount>.+)"
" (?P<network>.+)"
" @ (?P<rate>.+)"
" (?P<legal>.+)"
" (?P<contact>.+)")
{'operation': 'sell', 'amount': '2000', 'network': 'USDT', 'rate': '5.56', 'legal': '111.222.333-44', 'contact': 'user@example.com'}