0

I am new to using regex. I would like to use Notion to create a personal reference manager. My idea is to extract information from one column containing a bibtex entry to another column, that would contain, for instance, the title of the paper.

My idea that worked better so far:

replaceAll(
    replaceAll(prop("Bibtex"), "^((.|\n)*)[tT]itle(\\s|.*)=(\\s|.*){", ""),
    "}((.|\n)*)",
    ""
)

but it fails if the title has any curly brackets. For instance, the Bibtex entry

@article{xu2015experimental,
    title = {Experimental Detection of a Majorana Mode in the core of a Magnetic Vortex inside a Topological Insulator-Superconductor ${\mathrm{Bi}}{2}{\mathrm{Te}}{3}/{\mathrm{NbSe}}_{2}$ Heterostructure},
    author = {Xu, Jin-Peng and Wang, Mei-Xiao and Liu, Zhi Long and Ge, Jian-Feng and Yang, Xiaojun and Liu, Canhua and Xu, Zhu An and Guan, Dandan and Gao, Chun Lei and Qian, Dong and Liu, Ying and Wang, Qiang-Hua and Zhang, Fu-Chun and Xue, Qi-Kun and Jia, Jin-Feng},
    journal = {Phys. Rev. Lett.},
    volume = {114}, issue = {1},
    pages = {017001},
    numpages = {5},
    year = {2015},
    month = {Jan},
    publisher = {American Physical Society},
    doi = {10.1103/PhysRevLett.114.017001},
    url = {https://link.aps.org/doi/10.1103/PhysRevLett.114.017001} }

becomes

@article{xu2015experimental,
   title = {Experimental Detection of a Majorana Mode in the core of a Magnetic Vortex inside a Topological Insulator-Superconductor ${\mathrm{Bi

instead of

Experimental Detection of a Majorana Mode in the core of a Magnetic Vortex inside a Topological Insulator-Superconductor ${\mathrm{Bi}}{2}{\mathrm{Te}}{3}/{\mathrm{NbSe}}_{2}$ Heterostructure

Any help would be appreciated.

Rodo
  • 43
  • 3
  • 1
    chuck into your question some sample data and the expected output. Also, you can try using https://regex101.com/ to share examples. – sniperd Jun 27 '22 at 16:42
  • 1
    What is your expected output? Just the title after the "title={"? Please edit your post to show example good and bad titles please. – Gary_W Jun 27 '22 at 21:20
  • Your question is so unclear it's not answerable, so it's been closed. What exactly do you mean by "just the title"? From your only example, do you want `Majorana zero modes in impurity-assisted vortex of LiFeAs superconductor` or `title={Majorana zero modes in impurity-assisted vortex of LiFeAs superconductor}`? You mention problems with curly brackets in titles, but have not shown an example. Please edit your question to improve clarity, remove irrelevancies and add several examples of kinds of input and what you want matched from them. Then vote to reopen. – Bohemian Jun 27 '22 at 21:54
  • Hi, I have edited. – Bruna Mendonça Jun 27 '22 at 22:06

1 Answers1

0

If I understand, make the match for any character or newline non-greedy and anchor to the start of the line.

^[tT]itle={((.|\n)*?)},

regex101.com example

Edit: This works for also for the new example (allowing for optional whitespace before the word title and around the equal sign):

^\s*?[tT]itle\s?=\s?{((.|\n)*?)},
Gary_W
  • 9,933
  • 1
  • 22
  • 40