Hi i have line where i want to replace tab in double quotes. I have wrote script for that but it is not working as I want.
Q3U962 Mus musculus MRMP-mouse Optimization "MRMP-mouse "
for repline in reppepdata:
if len(findtorep) >0:
for repitem in findtorep:
Q3U962 Mus musculus MRMP-mouse Optimization "MRMP-mouse"
Q3U962 Mus musculus MRMP-mouseOptimization "MRMP-mouse"
Q3U962\tMus musculus\tMRMP-mouse\tOptimization \t"MRMP-mouse\t"
NOTE: This answer assumes (it is confirmed by OP) that there are no escaped quotes/sequences in the input.
You may match the quoted string with a simple
"[^"]+" regex that matches a
", 1+ chars other than
" and a
", and replace the tabs inside within a lambda:
import re s = 'Q3U96 Mus musculu MRMP-mous Optimizatio "MRMP-mouse "' res = re.sub(r'"[^"]+"', lambda m: m.group(0).replace("\t", ""), s) print(res)
See the Python demo