Python: re.sub使用lambda函数作为参数Python: re.sub使用lambda函数作为参数Python: re.sub使用lambda函数作为参数Python: re.sub使用lambda函数作为参数
  • 首页
  • 博客
  • 书签
  • 文件
  • 分析
  • 登录

Python: re.sub使用lambda函数作为参数

发表 admin at 2022年3月5日
类别
  • RegExp
标签
import re

word_string = """
<head>iph</head>
"""
regular = "<.*?>((\w*)(<.*?>))"
result = re.sub(regular, lambda x:x.group(2), word_string)
print(result)

运行结果:

iph

Process finished with exit code 0

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

类别

  • Cat
  • Python
  • MySQL
  • Django
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • php
  • Practice
  • Virtualization
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • Router
  • Office
  • WordPress
  • SEO
  • English
  • Games
  • Recipes
  • living
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2023 艾丽卡 Blog support@alaica.com
      ajax-loader