我有以下输入字符串
string = ['sql ddlsql144.internal.ecnahcdroffilc.net',
'fra-sql-03.internal.ecnahcdroffilc.net bro',
'esc-cca3cdr-12.internal.ecnahcdroffilc.com',
'au-per-06a-stwp-01.per.asia.ecnahcdroffilc.com',\
'http://go.fotrscomi.com',
'http //go.fotrscomi.com',
'fotrscomi.windows.computer',
'printers-03.internal.clif 10.51.59.10 roalswinds.oionr']
我希望结果是
['ddlsql144',
'fra-sql-03',
'esc-cca3cdr-12',
'au-per-06a-stwp-01'
'10.51.59.10' ]
匹配模式的条件是:
.com
或.net
结尾的url都应匹配,但不应以https://
或http://
或http //
开头url
的第一部分必须返回我试过了
expression = "(\w[-.a-z0-9]*)..?(?=org|net|com)"
# to extract the whole url
urls = re.findall(expression, str(string))
得到我用过的第一部分
re.findall('(^\w.+?)\.',str(urls))
但这并没有给我预期的结果。你知道吗
具有
re.search
函数和特定正则表达式模式的扩展解决方案:输出:
相关问题 更多 >
编程相关推荐