我有一个正则表达式对象和日期格式化程序的替换代码
简化代码如下:
assembledString = myRegex.sub(r"\2\3\4\5\6", textToChange)
#Where \2 , \3 ,\4 etc. are the groups of my regular expression object.
所以assembledString
由放在一起的组组成,但是我想在组“\3”和“\4”之间插入数字“0”。但是,当我这样做时,它被读取为'\30',即组30。类似地,当我在替换字符串中保留空格时,例如r“\2\3 0\4\5\6”,空格也被插入assembledString
我尝试过连接替换字符串以及使用转义字符和引号,但没有找到解决方案
非常感谢
它通常不应该这样解释,但是如果您已经尝试了所有其他方法,并且为运行添加一点时间不是问题,那么请尝试分两步执行
首先,您不仅添加了“0”,而且还添加了一些在其他任何地方都找不到的奇怪单词,接下来,您只将该单词替换为null“”
您可以使用
\g<number of group>
(doc)。从文件:印刷品:
相关问题 更多 >
编程相关推荐