The goal is to find LATEX index entries that might have one or two arguments. In addition, the entries might use lowercase or uppercase mode. So, we have to search for either of the following:
• A backlash followed by some characters and index (lower- or uppercase) and then the index
entry surrounded by braces for something like the following:
index{STL}%
MAININDEX{standard template library}%
• A backlash followed by some characters and index (lower- or uppercase), and then the index
entry and a “see also” entry surrounded by braces for something like the following:
SEEINDEX{standard template library}{STL}%
Using the egrep grammar, we can put a newline character between these two regular expressions. (In fact, grep and egrep can search for multiple regular expressions at the same time, specified in separate lines.) However, we have to take greediness into account, which means that we have to ensure that the first regular expression does not also match the sequences that should match the second regular expression. So, instead of allowing any character inside the index entry, we have to ensure that no braces occur. As a result, we have the following regular expressions: