尝试获取 domain.zz 或 domain.zzz 或 domain.zz.zz 或 /something。
import re
the_string = """lalalla?url=http2F%2Fdomain.zz%slgkfgs0s"""
the_string = """lalalla?url=http2F%2Fdomain.zz.zz/something%slgkfgs0sf"""
the_string = """lalalla?url=randomh564domain.zzz/something%slgkfgs0sf"""
the_string = """lalalla?url=randomeefsdlk876%domain.zz/something%slgkfgs0sf"""
the_string = """p%3A%2F%2Fdummy_test.com/ratata%2F&"""
the_string = """p%3A%2F%2Fdum2test.co.uk/something%2F&-kj"""
这就是我现在拥有的:
>>> print( re.findall('(?:www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4})(?:/[a-z0-9]+)',the_string))
domain.zzz/something
domain.zz/something
domain.zz.zz/something
>>> print( re.findall('www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}',the_string))
domain.zzz
domain.zz
domain.zz.zz
我想让这两组人回答一个问题。
编辑:这个几乎是完美的:'([a-z0-9.-]+[.][az]{2,4})|(?:/[a-z0-9]+)' 但它抓住了字符串开头的一些垃圾。
该字符串比本例中的随机得多:我关注的是这 3 种情况:
domain.co.uk/something
^ ^ ^
domain.com/something
^ ^
domain.com
^