How to find a text between two characters and replace it by a text between another two characters of a line in notepad++?

sayros

I have many lines of bibliography as the following:

@article{mehri_buckling_2016, title = {Buckling }, doi = {10.1016/j.cma.2016.01.017}}

@article{jin_modified_2014, title = {A modified ns}, doi = {10.1016/j.apacoust.2014.04.007}}

@article{sofiyev_free_2017, title = {The free}, doi = {10.1016/j.compositesb.2017.03.054}}

@article{malekzadeh_three-dimensional_2012, title = {Three-dimensional free }}

@article{jooybar_thermal_2016, title = {Thermal panels}, doi = {10.1016/j.tws.2016.01.032}}

In each line may there is doi={...} or not. I need to replace the words between @article{......, by the word between doi = {...}, if there is doi in its line.

For this example results should become:

@article{10.1016/j.cma.2016.01.017, title = {Buckling }, doi = {10.1016/j.cma.2016.01.017}}

@article{10.1016/j.apacoust.2014.04.007, title = {A modified ns}, doi = {10.1016/j.apacoust.2014.04.007}}

@article{10.1016/j.compositesb.2017.03.054, title = {The free}, doi = {10.1016/j.compositesb.2017.03.054}}

@article{malekzadeh_three-dimensional_2012, title = {Three-dimensional free }}

@article{10.1016/j.tws.2016.01.032, title = {Thermal panels}, doi = {10.1016/j.tws.2016.01.032}}
trincot

You could do it like this:

  • Find what: ^(@article\{).*?(,.*?doi = \{)(.*?)\}
  • Replace with: \1\3\2\3}
  • Regular expression: checked
  • . matches newline: cleared

Explanation:

  • ^ is maybe optional, but it ensures that the match can only occur at the beginning of a line.
  • (@article\{) matches literally @article{. The brace had to be escaped with a backslash, as it is a special character in regexes. The parentheses make it possible to refer to this string with \1 later. It's a so called "capture group"
  • .*? will match any series of characters , but not more than necessary to get a complete match ("lazy"): . means any character, * any number of them, ? but as few as possible to make the rest work.
  • (,.*?doi = \{) matches a literal comma, then again some more characters (see previous point), followed by a literal doi = {. The parentheses make it possible to refer to this as \2 later.
  • (.*?) matches a number of characters (see above). The parentheses make it possible to refer to this as \3 later. This is the part that matches the actual text that needs to be copied.
  • \} a literal }.

The replacement uses the capture groups:

  • \1 is synonymous for @article{
  • \3 is the text that needs to be copied
  • \2 is whatever appeared between , and doi = {, including those two texts.
  • \3 is repeated to just restore the doi value as it was.
  • } is the closing brace that was matched at the end of the "find" pattern. We want to keep it as well of course.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to find a text between two characters and replace it by a text between another two characters in notepad++?

How to find text in between two characters

Javascript - Find all text between two characters and replace that text

How do I delete text between two characters in notepad++

How can I delete text between two characters for Notepad ++?

Replace text between two characters in mysql

JavaScript replace text between two special characters

replace text lines between two characters

How to replace string between two characters in whole text?

How to select text between two characters in a RichTextBox

Get text between two characters

return text between two characters

Regex match failing to find text between two characters

Find text between the first two same characters of my choice with regex

Find Text between special characters and replace string

Google Sheets Extract Text between two characters

Oracle SQL: Extracting text between two characters

Finding text between two specific characters or strings

Remove text that is between two specific characters of a string

Filter text between two special characters

GWT - extract text in between two characters

PowerShell - lowercase text between two characters

Regex to get text between two characters in Java

Intelligently fetch text between two characters

Extracting Text Between two Characters in Excel

JavaScript Regex to filter text between two characters

Removing all text between two sets of characters

Remove text between two characters in Unix

If between two different characters in a text file, Python