Search code examples
pythonregexpython-re

Remove double quotes only if it between character Python


I have a string inside variable a contains double quotation inside double quotations :

Input :

a = ""comment_text": "Siti Sa"diah I need this for my neighbor needs""

Expected result :

a = ""comment_text": "Siti Sadiah I need this for my neighbor needs""

I tried using

re.sub(r'[^A-Za-z]', '', a)
and I also tried this one:
re.sub('"', '', a)

but it resulting like this :

commenttextSitiSadiahIneedthisformyneighborneeds
and this
comment_text: Siti Sadiah I need this for my neighbor needs

I want to delete double quotation(") only if it between alphabets.

I'm using python for this one. Is anyone could find a way to solve this issue ?

Thanks a lot!


Solution

  • re.sub(r'(\w)"(\w)', r'\1\2', df['comment']) for any word character around "