Python Forum
Regex Subdomain Validation & Input website manual
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex Subdomain Validation & Input website manual
#1
Hello,
I have some code like this

import re, urllib

GRUBER_URLINTEXT_PAT = re.compile("(https?://)([^:^/]*)(:\\d*)?(.*)?")

for line in urllib.urlopen("https://pastebin.com/raw/hvGXKp72").readlines():
    print [ str(mgroups[1]).replace('\r\n','') for mgroups in GRUBER_URLINTEXT_PAT.findall(line) ]
this code to read
example.com
only without HTTP,HTTPS & WWW
Now i have a question , how to valid the Subdomain ? e.g
subdomain.example.com
is readable with the code?
and how to input manual the link website from
("https://pastebin.com/raw/hvGXKp72")
? e.g
Please Input Your Website :
then input the website manually.

Thank you in advace,
I hope anybody can help me.

Sorry for my bad english Angel Tongue
Reply
#2
Well, re.compile("(https?://)?([^:^/]*)(:\\d*)?(.*)?") will only catch the http(s) if it is there, and will match example.com. It will also match subdomain.example.com, but all of that will be in the second group. Is that what you wanted or did you want the subdomain to be in a separate group?

As for asking for user input, that's easy:

url = input('Please input your website: ')
match = GRUBER_URLINTEXT_PAT.match(url)
if match is None:
    print('Invalid url.')
else:
    print('That url is valid.')
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked Manual Splines? Power_Broker 4 1,103 Nov-08-2022, 01:49 AM
Last Post: Power_Broker
  input data validation plumberpy 2 1,747 Aug-11-2021, 12:04 PM
Last Post: plumberpy
Question Input validation goes south. Gilush 6 2,620 Dec-04-2020, 12:18 PM
Last Post: Gilush
  py2 to py3 manual conversion, dictonaries Vysero 8 5,047 Jun-06-2018, 08:33 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020