regex - 如何在准确文本之前在 Notepad++ 中查找和替换?
问题描述
我有一个包含数千行(json 列)的文件,如下所示:
"128", "drugName_en": "Ampy 500mg 胶囊", "drugName_ar": "امبي 500 مجم كبسول", "scientificDrugId": "959", "proxyDrugId": "01", “prodCompDrugId”:“06”, "pack": "2x10Capsules", "unit": "باكت", “价格”:“0”, “折扣”:“00”, "categoryId": "15", “图像”:“ http://icons.iconarchive.com/icons/graphicloads/medical-health/256/medicine-box-icon.png ” }, "129", "drugName_en": "Ampy C 10*10 C 500mg 胶囊", "drugName_ar": "امبي سي 500 مجم 10*10 كبسول", "scientificDrugId": "36", "proxyDrugId": "01", “prodCompDrugId”:“06”, "pack": "10x10Capsules", "unit": "باكت", “价格”:“2267”, “折扣”:“00”, "categoryId": "15", “图像”:“ http://icons.iconarchive.com/icons/graphicloads/medical-health/256/medicine-box-icon.png ” },
我需要将,
之前的每个"drugName_en"
替换为:{
这可以在记事本++中完成吗?
先感谢您。
解决方案
这可以完成工作,保留换行符(无论它是什么):
- Ctrl+H
- 找什么:
,(\R)(?=\s+"drugName_en")
- 用。。。来代替:
:{$1
- 检查 火柴盒
- 检查 环绕
- CHECK 正则表达式
- Replace all
解释:
, # a comma
(\R) # group 1, any kind of linebreak (i.e. \r, \n, \r\n)
(?= # positive lookahead, make sure we have after:
\s+ # 1 or more white spaces
"drugName_en" # literally
) # end lookahead
替代品:
/{ # literally
$1 # content of group 1, the linebreak
屏幕截图(之前):
屏幕截图(之后):
推荐阅读
- angular - 当所有 XHR 请求完成时做一些事情 - Angular 7
- here-api - 检索速度类型与速度类别
- visual-studio-code - 带有 Webview 的 VS 代码扩展以连接到 API
- ruby-on-rails - Rails 5.2/Yarn:从节点模块导入 CCS 的正确方法是什么?
- nlp - 为什么损失继续减少而性能保持不变?
- java - 我的远程服务器 (Amazon EC2) 是否需要运行 2 台不同的服务器来运行 EmberJS 和 Spring Boot?
- javascript - 更改 Blob 文件名
- c++ - 在 c/c++ 中,二进制补码整数将 +1 转换为 -1 并将 0 转换为 1 的按位运算是什么?
- python - Django TemplateSyntaxError - 'staticfiles' 不是注册的标签库
- excel - 为许多连续行自动填充文本中的连续数字