Remove double quotes only if it between character Python

Question:

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!

Asked By: Johan Klemantan

||

Answers:

re.sub(r'(w)"(w)', r'12', df['comment']) for any word character around "

Answered By: markalex

Try this regex :

r'b"b'

The b is called a word boundary. It matches the position between a word character and a non-word character (in this case "), or the beginning or end of the string.

Demo here

Answered By: SelVazi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.