Analysis
The number is often a group of 3 numbers followed by a comma, so the rule is: ***,***,***
Regular type
The code is as follows:
[A-z]+,[a-z]?
The code is as follows:
Import re
Sen = "ABC,123,456,789,MNP"
p = re.compile ("\d+,\d+?")
For COM in p.finditer (SEN):
mm = Com.group ()
Print "Hi:", mm
Print "Sen_before:", Sen
Sen = sen.replace (mm, Mm.replace (",", ""))
Print "Sen_back:", Sen, ' \ n '
Skills
Using function Finditer (string[, pos[, Endpos]) | Re.finditer (pattern, string[, flags]):
Searches for a string that returns an iterator that accesses each matching result (match object) sequentially.
The code is as follows:
Sen = "ABC,123,456,789,MNP"
While 1:
MM = Re.search ("\d,\d", Sen)
if mm:
mm = Mm.group ()
Sen = sen.replace (mm, Mm.replace (",", ""))
Print Sen
Else
Break
Such a program for the specific problem, that is, the number 3 bit a group, if the numbers mixed with the letter, kill the comma between the numbers, that is, "ABC,123,4,789,MNP" into "ABC,1234789,MNP"
More specifically, find the regular "numbers, numbers," and then remove the comma after the replacement
The code is as follows:
Sen = "ABC,123,4,789,MNP"
While 1:
MM = Re.search ("\d,\d", Sen)
if mm:
mm = Mm.group ()
Sen = sen.replace (mm, Mm.replace (",", ""))
Print Sen
Else
Break
Print Sen