python - Replace all the occurrences of consecutive repeated pair of values -


I have a string with repeated repeated comos, and I want to insert a character between coma, for example What is this when I run re.sub for:

  re.sub (r ",,", ", 0,", "a ,,,,, ,,,,,, a ", '' a, 0, 0, 0, 0, 0, 0 ,, 0, a ''  / Pre> 

and the result I want is all the replacement, such as:

  'a, 0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, a ' 

I understand why this is happening, pai Overlapping in the turn, but I do not know how to fix it.

You can use a letterhead, for example:

  & gt; & Gt; & Gt; Re.sub (r ", (? =,)", ", 0", "a ,,,,,,,,,,,, a") 'A, 0,0,0,0,0,0, 0,0, 0,0,0,0,0,0,0,0,0, a ' 

or alternatively without regular expressions:

  & Gt; & Gt; & Gt; "," ".," A,., (",") "., ', 0,0,0,0, in x for X or" 0 "0,0,0,0,0,0,0, 0,0,0, a ' 

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -