用正则式判断URL是否合法-python

import sys
import re
#Make sure we have a single URL argument.

if len(sys.argv) != 2:
    print (sys.stderr, "URL Required")
    sys.exit(-1)
#Easie access.
url = sys.argv[1]
#Ensure we were passed a somewhat valid URL.
#This is a superficial test.
if re.match(r'^https?:/{2}\w.+$', url):
    print("This looks valid.")
else:
    print("This looks invalid.")

用正则式判断URL是否合法-python

终于进入到正则表达式的学习了。

PyCharm真是个不错的IDE呢,免费版于我暂时够用罗~~

re.match(r'^https?:/{2}\w.+$', url)

上一篇:CSS之viewport 1


下一篇:SqlSever中Index Seek的匹配规则(一)