我正在寻找一个正则表达式来删除字符串中的每个url或域名,以便:
string='this is my content domain.com more content http://domain2.org/content and more content domain.net/page'
变成
^{pr2}$移除最常见的TLD对我来说已经足够了,所以我尝试了
string = re.sub(r'\w+(.net|.com|.org|.info|.edu|.gov|.uk|.de|.ca|.jp|.fr|.au|.us|.ru|.ch|.it|.nel|.se|.no|.es|.mil)\s?','',string)
但这是删除了太多的东西,而不仅仅是网址。正确的语法是什么?在
你应该逃出所有这些点,或者更好的是,把这个点移到组外,然后逃逸一次,你也可以从not space直到not space,像这样:
以下内容:
^{pr2}$'this is my content domain.com more content http://domain2.org/content and more content domain.net/page thingynet stuffocom'
变成:
这是另一种解决方案:
输入:
^{pr2}$输出:
相关问题 更多 >
编程相关推荐