I have a small parser that should be able to parse the message
bellow, the last group in the message is the email, which is optional.
Unfortunately, with my current regex I was unable to get the email, the regex returns None/null on email group.
What I need to do to email can be captured and be optional?
import re
# message = "/sell 2000 USDT @ 5.56 111.222.333-44 +123456789"
message = "/sell 2000 USDT @ 5.56 111.222.333-44 +123456789 mail@example.com"
parser = re.compile(
r"""
^/
(?P<operation>buy|sell)
\s
(?P<amount>.+)
\s
(?P<network>.+)
\s
@
\s
(?P<rate>.+)
\s
(?P<legal>.+)
\s
(?P<cellphone>.+)
\s?
(?P<email>.+)?
$
""",
re.VERBOSE,
)
result = parser.match(message)
group = result.groupdict()
print(group)