繁体   English   中英

python REGEX - 如何从字符串中删除方括号?

[英]python REGEX - How Do I remove Square brackets from string?

A = """ 这是我的 [name duty 受到解决时间的情况],最后我叫了 "man \fjd" 所以你照顾那个东西。"""

这是一个随机字符串,可能类似于我的问题。

我想像这样 output

[名称职责受到解决 - 时间情况###没有方括号但在 python 中使用finditer我也需要解决方案

括号内的 man \fjd ### 材料使用 re.finditer ....

    a= """This is my [name Duty subjected to solve  - time situation ] and finally I called "the man \fjd " so you take of care of that thing."""
pattern ='''         I nEDD THIS ANSwers                                  '''
    for item in finditer(pattern ,a, re,VERBOSE :
       return(item.groupdict())

为什么只需要正则表达式来删除方括号? 您可以简单地使用替换来完成工作!

a = a.replace('[', '').replace(']', ''])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM