I want to use search & replace with a regular expression to turn the following text:
"some text i dont care about \cite[p. 6]{some-bibtex-citation}
some more text I care even less about \cite[p. 321 / 4]{and-another-citation-from-bibxtex} and still more text."
into this:
"some text i dont care about [\citem{author}{some-bibtex-citation}, p. 6]
some more text I care even less about [\citem{author}{and-another-citation-from-bibxtex}, p. 321 / 4]
and still more text."
As you can see, all of the \cite occurences have been replaced with a different one. They are now surrounded by [ and ] and they all start with [citem{author}
I tried it with the following search regex which basically works but can select too much text all at once:
\\cite\[(.+)\]\{(.+)\}
The replace regex I used for this is:
[\\citem{author}{\2}, \1]
Change your regex so that the .+
becomes lazy:
\\cite\[(.+?)\]\{(.+?)\} ^ ^
Making a greedy quantifier lazy means that instead of matching as much as possible, it will match as little as possible. In your current regex, the .
will match all the characters until it finds another )
(followed by the other characters in the regex).
Or use negated classes:
\\cite\[([^\]]+)\]\{([^}]+)\}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With