Search X num digit in text using Python

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

mail_text = ‘’’
====================================================================================================
Subject: Your Facebook security code
From: “Facebook”

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))

--

--

David Amirkhanov

I am programming ingeneer in WebSofter Inc and indi developer for few my own projects. My favorite stacks is JavaScript, Nodejs, Vue, Python and more