regex - Python:Replace tab in double quotes -


hi have line want replace tab in double quotes. have wrote script not working want. line:

q3u962  mus musculus    mrmp-mouse  optimization    "mrmp-mouse " 

my script:

    repline in reppepdata:     findtorep=re.findall(r"['\"](.*?)['\"]", repline)     if len(findtorep) >0:         repitem in findtorep:             repchar =repitem             repchar=repchar.replace('\t', '') 

my output should be:

q3u962  mus musculus    mrmp-mouse  optimization    "mrmp-mouse" 

but getting this:

q3u962  mus musculus    mrmp-mouseoptimization  "mrmp-mouse" 

words separated tab delimiter here.

q3u962\tmus musculus\tmrmp-mouse\toptimization \t"mrmp-mouse\t" 

anyone has idea how it?

note: answer assumes (it confirmed op) there no escaped quotes/sequences in input.

you may match quoted string simple "[^"]+" regex matches ", 1+ chars other " , ", , replace tabs inside within 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 python demo


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -