can you help me with regex to find all single quotes inside single quotes?
IE
'sinead o'connor','don't don't','whatever'
Thanks for any advice.
can you help me with regex to find all single quotes inside single quotes?
IE
'sinead o'connor','don't don't','whatever'
Thanks for any advice.
Seems like your string was separted by comma.
re.sub(r"\b'\b", "''", s)
or
(?<=[^,])'(?!,|$)
Example:
>>> import re
>>> s = "'sinead o'connor','don't don't','whatever'"
>>> re.sub(r"\b'\b", "''", s)
"'sinead o''connor','don''t don''t','whatever'"
>>>
You can achieve this even without regex:
>>> string = "'sinead o'connor','don't don't','whatever'"
>>> string = string.replace("'", "''")
"''sinead o''connor'',''don''t don''t'',''whatever''"
>>> string.strip("'")
"sinead o''connor'',''don''t don''t'',''whatever"