我正在尝试在特定行上应用特定的正则表达式,该行由起始键指定: 现在,我将文件的内容放在python变量my\u config中
file content
---------------------------------------------
[paths]
path_jamjs: C:/Users/[changeUsername]/AppData/Roaming/npm/node_modules/jamjs/bin/jam.js
path_php: C:/[changeUsername]/php/php.exe
values to replace
---------------------------------------------
"path_jamjs": { "changeUsername": "Te" },
"path_php": { "changeUsername": "TeS" },
with open ("my.ini", "r") as myfile:
my_config = myfile.read()
如何对我的配置中的整个文件内容应用regex replace来替换特定对应行上的值,而不必逐行循环,我可以用regex来完成吗?
给予
path: path_php
key: changeUsername
value: Te
改变
path_jamjs: C:/Users/[changeUsername]/AppData/Roaming/npm/node_modules/jamjs/bin/jam.js
path_php: C:/[changeUsername]/php/php.exe
至
path_jamjs: C:/Users/[changeUsername]/AppData/Roaming/npm/node_modules/jamjs/bin/jam.js
path_php: C:/Te/php/php.exe
相关问题 更多 >
编程相关推荐