Python re | How to use python regex module - codebugfree

Regex or re how to use 

In this section we learn the python regex module. regex is also known as re. Python short name is re. Regex is the main module to find the specific word from the string. Regex extact any thing like phone number email.

You can use this module in python. Install this module pip install regex write this command in your python ide terminal. 

Regex is most use by a hacker to find the phone number email password age. Does not use the regex for illegal purpose. We does not promote the illegal content. Regex have lot of the function and module.

Now we see the programmer or code of regex. Also describe the the one by one code shortly.

import re

long_string = ''' tha nks to visit my website ands thanks to 
good for coming my website [email protected] the social otf the good and 
most hacking vulnerabilitiees is social enginer ing it is most vulnearable 
[email protected] the [email protected] [email protected] '''
new_email = re.compile(r"[a-zA-Z0-9._-][email protected][a-zA-Z0-9._-]+[.][a-zA-Z0-9._-]+")#finding algoritham of gmail
finding = new_email.findall(long_string)
i =0
for email_generator in finding:
    with open("emailextract.txt","a")as email_write:

Here we first create the long string. Inside the string there are fake Gmail. Using re.compiler to make the algoritham of email. Finding the email with that long string.

Using the for loop to find all email from long string. All email generate from long string that save in file. With open the emailextractor.txt. save all email of his file. last print all element from long string.


[email protected]
[email protected]      
[email protected]
[email protected]

It is the output of the long string. With the helping of the regex or re module. we successfully find the email.

Find the email from website use of regex

Now we will see the example of regex and request module. Request is use to request the any webpage or website. Request the webpage and regex extact the email from backend of website.

import requests
import re

url = input("+ Enter a website url: ")
refine = requests.get(url).text

searchweb = re.compile("[a-zA-Z0-9._-][email protected][a-zA-Z0-9._-]+[.][a-zA-Z0-9._-]+")
email_finding = searchweb.findall(str(refine))
for email_finish in email_finding:

Import the request and regex re module. Input the url from the user. That url sent the request and generate the text. using the email finding algoritham finding the email.


+ Enter a website url:
['[email protected]']

Post a Comment