Answer to Question #255441 in Python for kyle

Question #255441
Create a program to develop a Regex that will find all website URLS that begin with http://www or https://www search for URL matches and then copy matches back to the clipboard. Display the matches on the screen and display the message “No web addresses found” if there are none.
1
Expert's answer
2021-10-23T23:31:34-0400
import re

def checkUrlValidity(str):

    
    regex = ("((http|https)://)(www.)?" +
            "[a-zA-Z0-9@:%._\\+~#?&//=]" +
            "{2,256}\\.[a-z]" +
            "{2,6}\\b([-a-zA-Z0-9@:%" +
            "._\\+~#?&//=]*)")
    
    
    x = re.compile(regex)

    if (str == None):
        return False

    
    if(re.search(x, str)):
        return True
    else:
        return False


url = "https://www.test.com"

if(checkUrlValidity(url) == True):
    print("matches on the screen")
else:
    print("No web addresses found")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS