![]() Table of Contents
|
Appendix C: Pike Regexp Syntax In LogView, Pike regular expressions are used to separate served files into different categories, like for example pages and non-pages, and also for specifying names of hosts to ignore in the statistics. Pike regular expressions are very powerful, as we will show in the following examples. Really, a Pike regexp is the same kind of regexp that is used by many UNIX tools, like egrep and awk, and the user who is experienced in this area may well stop reading right here, or jump directly to the reference chart to refresh his memory concerning the syntax.
Short introduction
Now for the special characters "." and "*". A "." matches one occurance of any character and a character followed by a "*" maches any number, even zero, of consequent occcurances of the character. This letter might also be a ".", in which case zero or more of any letter is matched. Thus, ".*" gives the same effect as a single "*" character given in a filename at a UNIX or DOS prompt, which can be a bit confusing. As can be noticed above, the first pattern also matched yyyyrhino.ceros.com, since "." is a special character. However, if we want to specify it to be matched as a normal character, we have to put the escape character, "\" in front of it. Now we've covered the basic stuff about simple regexps. However, there is also a possibility to use boolean functions to put together several simple regexps to complex ones - for example, (regexp1) | (regexp2) is a new regexp that matches a string if regexp1 or regexp2 matches the string, and similiarly (regexp1) & (regexp2) matches a string if both regexp1 and regexp2 matches the string. This is the complete reference chart for the Pike regexp syntax,
taken from the Pike manual.
Let's look at a few examples: Note that \ can be used to quote these characters in which case they match themselves, nothing else. Also note that when quoting these something in Pike you need to write \\ because Pike also uses this character for quoting. |