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

2025-06-12 00:58:45

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

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

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

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

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

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

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

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

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

如何用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
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢