4.3.4.5 Another Version of the Citation Program
4.3.4.5 Another Version of the Citation Program
We have seen that sometimes we may have two or more citation indices used in one use of \cite. In such cases, the indices are separated from each other by a comma. In the programs we have presented so far, one set of programs look for non-} characters inside the braces that follow \cite. These programs do not look to see if the citation indices follow the syntax we need them to have. The other set of programs look for only one citation index inside the braces following the use of
\cite. Therefore, in essence, both sets of programs are not strictly correct to achieve the goal we have set for ourselves. The program that we present next attempts to solve both of these problems. It looks for multiple citation indices that follow the syntax specified.
Program 4.11
#!/usr/bin/perl
while (<>){
if (/\\cite{([A-Z][a-zA-Z]*(19)?\d{2},)*[A-Z][a-zA-Z]*(19)?\d{2}}/){
print $_;
}
}
Here, each index is checked for the presence of an uppercase letter, followed by zero or more lowercase letters followed by two digits. The subpattern [A-Z][a-zA-Z]*(19)?\d{2} picks out one such index. However, we are looking for two or more such indices. Therefore, we break up the problem into two parts. In the first part, we look for zero or more occurrences of a subpattern where we have one citation index followed by a comma. In the second part, we then look for the occurrence of the last citation index. To look for the first part, we put the subpattern for a citation index followed by a comma into a group. We form a group by using
parentheses around the subpattern. In this case, this group is indicated by ([A-Z][a-zA-Z]*(19)?\d{2},). We then put an asterisk after this group to indicate that we are looking for zero or more occurrences of the subgroup. This is specified as ([A-Z][a-zA-Z]*(19)?\d{2},)*. Finally, we specify the second part of the problem by writing out once again the subpattern for an index.
