如果空格在双引号之间,我想替换一个空格来加下划线.示例:
given = 'hello "welcome to" python "blog"'
expected = 'hello "welcome_to" python "blog"'
我的实际字符串是SQL代码,我需要将其转换为使用下划线进行migrations.
我所try 的
import re
s = 'hello "welcome to" java 2 "blog"'
a = re.sub('(\"[\w\s]+\")', '_', s)
print (a)
我也在谷歌上试了又试,但还没有找到.
在Python中怎么做?