To an arbitrary string "ABC" continuous repetition (note is continuous repetition) of two or more times a string replaced with ABC: "abcaaebabcabcfdabcabcabc", for example, after operation, to become "abcaaebabcfdabc", by the way, can the regular match, to find for a long time, with regular online are of match of the character, as if unable to string matching, given a string matching match_str, replace another string in source_str match_str repeated more than twice continuously substring is match_str,
CodePudding user response:
S="abcaaebabcabcfdabcabcabc"
The import re
Li=re. Finditer (" (ABC) {2} ", s)
For I in li:
Print (i. pan ())
# matches of ABC occurrences to achieve two consecutive times and above the subscript
CodePudding user response:
S="abcaaebabcabcfdabcabcabc"
The import re
Sx="". Join (re. The split (r" (ABC) {2} ", s))
Print (sx)
Can directly replace # re theoretically. The sub, but my mobile phone can't match, can cut, this code can realize the function of your