Q:

Regex not giving expected result in python

I wrote this regex in an online editor and it was working properly there, but whenever I copy it to python, it can't find what I need anymore. Here is my code:
import requests
import re
import os

PAYLOAD = {
    "username": os.environ['USERNAME'],
    "password": os.environ['PASSWORD']
}

LOGIN_URL = "https://ringzer0ctf.com/login"
CHALLENGE_URL = "https://ringzer0ctf.com/challenges/32"

MESSAGE_REG_EX = r"(BEGIN MESSAGE -----<br \/>\n\n\t\t)(\d*)"

with requests.session() as session:
    session.post(LOGIN_URL, data=PAYLOAD)
    r = session.get(CHALLENGE_URL)
    print(r.text)
    num = re.search(MESSAGE_REG_EX, r.text).group(2)
    print(num)

I need to extract the first number between BEGIN MESSAGE and END MESSAGE which in this case is 6907.
    <div class="challenge-wrapper">

                <div class="padding_div">

        </div>

        <strong>You have 2 seconds to send the answer</strong><br />

        <strong>Send the answer back using https://ringzer0ctf.com/challenges/32/[answer]</strong>

        <br /><br /><br /><br /><br />

        <div class="message">

        ----- BEGIN MESSAGE -----<br />

        6907 + 0x1d68 - 1010001001100 = ?<br />

        ----- END MESSAGE -----<br />

        </div>

    </div>

<hr />

Error message:

num = re.search(MESSAGE_REG_EX, r.text).group(2)
  AttributeError: 'NoneType' object has no attribute 'group'

A:

Maybe - or spaces got outnumbered. Give a try to below regex,
MESSAGE_REG_EX = r"BEGIN MESSAGE -{3,}<br\s*\/>\s*(\d+)" 
match = re.search(MESSAGE_REG_EX, r.text)
if match:
    print (match.group(1))
else:
    print('Failed to find a match :(')

