python-3.x - 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).
我怎样才能最容易地建立一个可以替换上述阀门的模式?
解决方案
推荐阅读
- webassembly - Emscripten 使用 USE_ICU = 1 构建并且在调用 ubrk_open() 后总是以 U_MISSING_RESOURCE_ERROR 失败
- typescript - VSCode 扩展 - 如何编辑工作区全局配置?
- airflow - MultiTennant Airflow - 访问控制和机密管理
- excel - 带有 OR 条件的 COUNTIFS 给出#SPILL!因此
- opencv - opencv read() 函数在 python idle shell 中运行良好。从 python ./image_handler.py 开始工作不好
- azure-web-app-service - 如何一步一步将两个azure linux虚拟机连接在一起
- typescript - ESLint - 每次导入的“no-unused-vars”警告
- html - css box-shadow 没有隐藏在滚动条上
- php - 重定向视图后会话仍然提交
- sql - 大量警告会导致 SSIS 包失败/取消吗?