Python regular substitution problem

problem description

there is a string style= "font-family: Microsoft Acer; font-size: 6.67pt; vertical-align: super" > 1code 2 . I want to replace 1Mague 2 with [1Mague 2] , where 1Mague 2 is just an example that may have multiple numbers but are all separated by , .

the environmental background of the problems and what methods you have tried

I don"t know what to do after matching to 1 and 2, change the original string

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

there is a string style= "font-family: Microsoft Acer; font-size: 6.67pt; vertical-align: super" > 1code 2 . I want to replace 1Mague 2 with [1Mague 2] , where 1Mague 2 is just an example that may have multiple numbers but are all separated by , . For advice, thank you! Beg urgently!

Mar.25,2021

you are advised to be flexible in dealing with this problem.

replace can I do it?
Yes. Of course there are limitations. Why don't we just try to change > < to [] < ?
replace ('">','> [') , which replaces the left.
right replace ('','] ')
blame low.

regular expression

  

Why should you replace it with a regular match? if it is an entire HTML document, you can borrow beautifulsoup to parse it and modify it in batches.

Menu