1

In Notepad++, I would like to replace all references/citations with a citation key.

E.g., the following:

Bla bla bla bla (van Author et al., 2015). 
Bla bla bla (Authorone, Authortwo, & Authorthree, 2016). 
Bla bla (Authorone & Authortwo, 2017). 

Should become:

Bla bla bla bla (vanAuthor2015). 
Bla bla bla (Authorone2016). 
Bla bla (Authorone2017). 

Note that there might also be multiple references in a single line, but there are no nested parentheses.

In a first step I replaced (?<=\([a-z][a-z][a-z])\s with nothing to turn the first citation from (van Author et al., 2015) into (vanAuthor et al., 2015). This would also work for (von Author et al., 2015).

Explanation:

  • \s Remove single white space
  • (?<= that follows
  • \([a-z][a-z][a-z]) an opening parenthesis and 3 lower-case letters.
  • ) close positive lookbehind.

However, I am struggling with the 2nd step. How can I replace the first whitespace until the last whitespace after a comma \s.*,\s only within parentheses? I read many posts titled "regex only in brackets" but the solutions I came across did not appear to apply to my case.

Community
  • 1
  • 1
Flo
  • 1,503
  • 1
  • 18
  • 35

1 Answers1

1

You may use

(\(\w+)(?:\s+(\w+))?[^)]*\s(\d+\))

and replace with $1$2$3.

Pattern details:

  • (\(\w+) - Group 1: a ( and then 1+ word chars
  • (?:\s+(\w+))? - an optional non-capturing group matching 1+ whitespaces and then capturing into Group 2 one or more word chars
  • [^)]* - zero or more chars other than )
  • \s - whitespace
  • (\d+\)) - Group 3: 1+ digits and ).

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563