Search code examples
replacenotepad++bracketsquotation-marks

How to replace quotation marks in front of and at the end of a string with brackets?


I'm trying to replace quotation marks with brackets like {}. I need to convert data for a bibtex import, which is not working with the quotation marks. It looks like this:

@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",  
}

And the whole file contains about 2000 records like this, plus abstracts which I've removed. I need to replace now all quotation marks in front and at the end of the strings with brackets. In the end it should look like this:

@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},  
}

Do you have any idea how I can do this? I've tried notepad++ and multiple replacement expressions but without success.


Solution

    • Ctrl+H
    • Find what: ^.+?=\h*\K"(.+)"(?=,)
    • Replace with: {$1}
    • CHECK Wrap around
    • CHECK Regular expression
    • UNCHECK . matches newline
    • Replace all

    Explanation:

    ^           # 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
    

    Screen capture (before):

    enter image description here

    Screen capture (after):

    enter image description here