This is my solution, in C++ with boost regex. Hope it helps someone :-)
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string_regex.hpp>
#include <boost/regex.h>
using namespace std;
using namespace boost;
int Section::countCitations() {
string Personsname = "([A-Z][a-z'`-]+)"; // Apostrophes like in "D'Alembert" and hyphens like in "Flycht-Eriksson".
string YearPattern = "(, *(19|20)[0-9][0-9]| ?\( *(19|20)[0-9][0-9]\))"; // Either Descartes, 1990 or Descartes (1990) are accepted.
string etal = "( et al.?)"; // You may find this
string andconj = Personsname + " and " + Personsname;
string commaconj = Personsname + ", " + "(" + Personsname + "|"+"et al.?"+")"; // Some authors write citations like "A, B, et al. (1995)". The comma before the "et al" pattern is not rare.
string totcit = Personsname+"?"+etal+"?"+"("+andconj+"|"+commaconj+")*"+etal+"?"+YearPattern;
// Matches the following cases:
// Xig et al. (2004);
// D'Alembert, Rutherford et al (2008);
// Gino, Nino and Rino, Pino (2007)
// (2009)
// Gino, et al. (2005)
cout << totcit << endl;
regex citationform(totcit);
int count = 0;
string_range citation;
string running_text(text.begin(), text.end() );
while ((citation = find_regex(running_text, citationform)) ) { // Getting the last one
++count;
string temp(running_text.begin(), citation.end() );
running_text = running_text.substr( temp.length()-1 );
}
return count;
}
answered 2012-05-10T12:01:07.063