【问题标题】:How to replace quotation marks in front of and at the end of a string with brackets?如何用括号替换字符串前后的引号?
【发布时间】:2020-01-17 15:14:40
【问题描述】:

我正在尝试用 {} 等方括号替换引号。我需要为 bibtex 导入转换数据,这不适用于引号。它看起来像这样:

@article{NASIR20159,  
title = "Fault-tolerant context development and requirement validation in ERP systems",  
journal = "Computer Standards & Interfaces",  
volume = "37",  
pages = "9 - 19",  
year = "2015",  
issn = "0920-5489",  
doi = "https://doi.org/10.1016/j.csi.2014.05.001",  
url = "http://www.sciencedirect.com/science/article/pii/S0920548914000695",  
author = "S. Zafar Nasir and Tariq Mahmood and M. Shahid Shaikh and Zubair A. Shaikh",  
keywords = "Context development, Requirement validation, Enterprise Resource Planning, Fault tolerance, Data Mining",  
}

整个文件包含大约 2000 条这样的记录,以及我删除的摘要。我现在需要用括号替换字符串前面和结尾的所有引号。最后应该是这样的:

@article{NASIR20159,  
title = {Fault-tolerant context development and requirement validation in ERP systems},  
journal = {Computer Standards & Interfaces},  
volume = {37},  
pages = {9 - 19},  
year = {2015},  
issn = {0920-5489},  
doi = {https://doi.org/10.1016/j.csi.2014.05.001},  
url = {http://www.sciencedirect.com/science/article/pii/S0920548914000695},  
author = {S. Zafar Nasir and Tariq Mahmood and M. Shahid Shaikh and Zubair A. Shaikh},  
keywords = {Context development, Requirement validation, Enterprise Resource Planning, Fault tolerance, Data Mining},  
}

你知道我该怎么做吗?我已经尝试过 notepad++ 和多个替换表达式,但没有成功。

【问题讨论】:

标签: replace notepad++ brackets quotation-marks


【解决方案1】:
  • Ctrl+H
  • 查找内容:^.+?=\h*\K"(.+)"(?=,)
  • 替换为:{$1}
  • 检查 环绕
  • CHECK 正则表达式
  • 取消选中 . matches newline
  • 全部替换

说明:

^           # beginning of line
  .+?       # 1 or more any character but newline, not greedy
  =         # equal sign
  \h*       # 0 or more horizontal spaces
  \K        # forget all we have seen until this position
  "         # double quote
  (.+)      # group 1, 1 or more any character but newline
  "         # double quote
  (?=,)     # positive lookahead, make sure we have a comma after

屏幕截图(之前):

屏幕截图(之后):

【讨论】:

  • 太棒了,谢谢托托。只有一件事不起作用。我已经提到我已经排除了摘要,因为它很长。但是现在有了你的解决方案,除了抽象线之外,每一行都得到了正确的改变。它看起来几乎相同,但更长,并且始终是最后一行,直到一条记录结束。像所有其他行后面一样,它后面没有逗号会有所不同吗?
  • @robinmathar:只需从正则表达式中删除前瞻 (?=,)。它应该工作。告诉我它是否有效。
  • 效果很好,我可以直接将它导入我的文献计量分析中。非常感谢,让我开心!
猜你喜欢
  • 2013-08-14
  • 2019-12-18
  • 1970-01-01
  • 2015-04-16
  • 2018-11-28
  • 2017-12-02
  • 2019-05-22
  • 2015-07-30
  • 2019-07-31
相关资源
最近更新 更多