Оценок пока нет Search X num digit in text using Python

import re

def get_code(text, length = 8):                            
    pattern= r"\D(\d{%d})\D" % length           
    code = re.findall(pattern, text)
    return code[0]


mail_text = '''
====================================================================================================
Subject: Your Facebook security code
From: "Facebook" <security@facebookmail.com>

Your Facebook security code

Hi David,Your security code is: 46875967 To help us confirm your identity on Facebook, we need to verify your email address. Paste this code into your browser. It can only be used once. If you didn't request a code, someone may be trying to access your account. To make sure your account is secure you can change your password.

Thanks,The Facebook Security Team



========================================
This message was sent to mail.websofter@yandex.ru at your request.
Facebook, Inc., Attention: Community Support, 1 Facebook Way, Menlo Park, CA 94025
'''       
print(get_code(mail_text))

Пожалуйста, оцените материал

WebSofter

Web - технологии