简体   繁体   中英

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

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. """

This is an random string probably similar to my problem.

I wanted to output like this

[name Duty subjected to solve - time situation ### Without square brackets but using finditer in python aslo I need solution for

the man \fjd ### material inside bracket using 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())

Why do you need regex just to remove the square brackets? You can simply use replace to get the job done!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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