Python Regular Expression

Extract Date in dd-mm-YYYY format from a string.
import re
my_string="Your birth day is on 24-12-2002""([0-9]{2}\-[0-9]{2}\-[0-9]{4})", my_string)
Output is here

Links ( URLs) from a file

import re
path='C:/dir_name/string_functions.php' # path of the file to read
fob=open(path,'r') # Open in read mode # collect data 
fob.close() # close file object 
urls1 = re.findall(r'href=[\'"]?([^\'" >]+)', data)
For case insensitive search use this.
urls1 = re.findall(r'href=[\'"]?([^\'" >]+)', data,re.IGNORECASE)

Searching string

import re
if'PLUS', 'Welcome to', re.IGNORECASE):
    print('It is there') # True 
    print('It is NOT there') # False
Output is
It is there
find(): searching string

All String methods

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer