首页 > 解决方案 > python re sub 替换值

问题描述

我需要一个 python 正则表达式,通过它我可以替换路径中的某些值

"path":"C:\Users\admin\Downloads\npp.8.0.Installer.exe"
"path": "C:\Program Files (x86)\Google\Common\Google Updater\Extensions\GoogleUpdaterService.exe"

"path":"<drive>:\Users\<uname>\Downloads\npp.8.0.Installer.exe"
"path": "<drive>:\Program Files (x86)\Google\Common\Google Updater\Extensions\GoogleUpdaterService.exe"

替换值为“<'drive'>”和“<'username'>”(如果路径中存在任何用户名)。

我正在尝试

re.sub(pattern, repl, string, count=0, flags=0). 

我怎样才能最容易地建立一个可以替换上述阀门的模式?

标签: python-3.xre

解决方案


推荐阅读