如何用PYTHON正则表达式来寻找URL

 时间:2024-10-12 14:10:18

1、打开JUPYTER NOTEBOOK,新建一个空白的PY文档。

如何用PYTHON正则表达式来寻找URL

2、#http://#https://这是一般的格式,我们需要找到这样的格式字符。

如何用PYTHON正则表达式来寻找URL

3、import re引入regular expression模块,然后才能运用相应的函数。

如何用PYTHON正则表达式来寻找URL

4、urlRegex = re.compile(r'http://')首先要在前面加上r来表示raw string。

如何用PYTHON正则表达式来寻找URL

5、urlRegex = re.compile(r'[a-z]{4}://')urlRegex.search(r'http://www.heyheyhey.com')http可以用26个字母来代替,然后注明4个字母。

如何用PYTHON正则表达式来寻找URL

6、urlRegex = re.compile(r'''[a-z]{4}://''')urlRegex.search(r'http://www.heyheyhey.com')建议用三引号来选中比较好。

如何用PYTHON正则表达式来寻找URL

7、urlRegex = re.compile(r'''\w{4}://''')urlRegex.search(r'http://www.heyheyhey.com')\w也是可以表示字母的。

如何用PYTHON正则表达式来寻找URL

8、urlRegex = re.compile(r'''[htps]{4}://''')urlRegex.findall(r'http://www.heyheyhey.com*****https://www.heyheyhey.com')中括号则可以指定字母,两个t只需要写一个。

如何用PYTHON正则表达式来寻找URL

9、urlRegex = re.compile(r'''^http://$''')urlR髫潋啜缅egex.findall(r'http://www.heyheyhey.com*****https://www.heyheyhey.com')urlRegex = re.compile(r'''^http://$''')urlRegex.findall(r'http://')用^和$只能针对字符首尾,不太适用在这里。

如何用PYTHON正则表达式来寻找URL

10、urlRegex = re.compile(r'''(http)(s?)(://)'''稆糨孝汶;)urlRegex.search(r'http://www.heyheyhey.com').group()urlRegex = re.compile(r'''(http)(s?)(://)''')urlRegex.search(r'https://www.heyheyhey.com').group()用问号表示零个或者多个。

如何用PYTHON正则表达式来寻找URL

11、urlRegex = re.compile(r'''http://|https://''')urlRegex.search(r'http://www.heyheyhey.com').group()urlRegex = re.compile(r'''http://|https://''')urlRegex.search(r'https://www.heyheyhey.com').group()用|字符表示或者。

如何用PYTHON正则表达式来寻找URL
  • 奥日和他的黑暗森林如何添加快捷方式
  • 剑姬怎么打酒桶
  • 堡垒之夜 怎样设置我们的在线状态为离开状态?
  • follow集怎么求
  • steam如何满速下载
  • 热门搜索
    宁夏旅游景点介绍 海南旅游岛 福州贵安温泉旅游度假村 旅游族 上海到俄罗斯旅游 夕阳红旅游专列 美东旅游 旅游团价格表 长葛旅游 北京旅游计划