4.3.4.2 +: One or more

4.3.4.2  +: One or more

  We can write another version of the program that actually works a little better in finding citations.

 Program 4.7

#!/usr/bin/perl

while (<>){
    if (/\\cite{[^}]+}/){
        print $_;
    }
}

In the program given above, the pattern we look for is the sequence \cite followed by a starting brace. Then we look for one or more characters from the negative character class [^}]. In other words, we are looking for one or more non-} characters. This is because the closing brace finishes our citation entry. We specify that we are looking for one or more characters from the negated class by surrounding the class description by a set of parentheses and putting the multiplier + after the closing parentheses. Here, the parentheses are used for grouping a subpattern. In this case, this example works with or without the parentheses. Specifically, we do not use a parenthesis pair here.

This program seems to find citations, but it is not strict enough in the sense that it does not look for the syntax of the string we are using as citation index. The index, as used by the author of the paper, consists of an uppercase letter, followed by zero or more other letters, followed by two digits giving the year of publication. We work toward more strict parsing in the following sections.