package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^@(.*?){(.*?),((.|\n)*?)+(}}|\n})+$`)
var str = `@inproceedings{martens2010deep,
title={Deep learning via Hessian-free optimization},
author={Martens, James},
booktitle={Proceedings of the 27th International Conference on Machine Learning (ICML-10)},
pages={735--742},
year={2010}
}
@article-journal{AAA,
url = {http://www.example.com},
year = {2016},
month = {},
publisher = {Elsevier},
journal = {{AAA Journal}},
author = {Austin Anderson and Austin Arnold},
title = {{Nothing To See Here}},
}
@article-journal{ZZZ,
url = {http://www.example.com},
year = {2016},
month = {},
publisher = {Elsevier},
journal = {{ZZZ Journal}},
author = {Austin Zyzygy},
title = {{Moving On Up}},
}
@article-journal{InstMed2001,
url = {http://www.ncbi.nlm.nih.gov/pubmed/25057539},
year = {2001},
month = {},
publisher = {{National Academy of Sciences}},
doi = {10.17226/10027},
volume = {},
number = {},
pages = {},
pmid = {25057539},
pmcid = {},
journal = {{}},
author = {{National Academy of Sciences}},
title = {{Crossing the Quality Chasm: A New Health System for the 21st Century}},
}
@article-journal{Wallace2013,
url = {http://apt.rcpsych.org/content/19/4/250},
year = {2013},
month = {July},
publisher = {{Royal College of Psychiatrists}},
doi = {10.1192/apt.bp.112.010389},
volume = {19},
number = {4},
pages = {250-258},
journal = {{BJPsych Advances}},
author = {John Wallace},
title = {{Lost in translation: transferring knowledge from research to clinical practice}},
}
@article-journal{Glasziou2005,
url = {http://ebn.bmj.com/content/8/2/36.full},
year = {2005},
month = {},
publisher = {{British Medical Journal}},
doi = {10.1136/ebn.8.2.36},
volume = {8},
number = {},
pages = {36-38},
journal = {{Evidence Based Nursing}},
author = {Paul Glasziou and Brian Haynes},
title = {{The paths from research to improved health outcomes}},
}
@article-journal{Glasziou2011,
url = {http://pmj.bmj.com/content/early/2011/06/29/pgmj.2010.116012.full.html},
year = {2011},
month = {June},
publisher = {{British Medical Journal}},
doi = {10.1136/pgmj.2010.116012},
volume = {},
number = {},
pages = {},
pmid = {},
pmcid = {},
journal = {{Postgraduate Medicine Journal}},
author = {Sharon Mickan and Amanda Burls and Paul Glasziou},
title = {{Patterns of 'leakage' in the utilisation of clinical guidelines: a systematic review}},
}
`
var substitution = "{\"id\":\"${2}\",\"type\":${1},\"content\":[{${3}]}}"
fmt.Println(re.ReplaceAllString(str, substitution))
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/