(copyright +(?:©|\(c\)|&copy;) +\d{4})(?: *[-,] *\d{4})* \1-2005 Update copyright statements \b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}\b Find email addresses <TITLE>.*?</TITLE>(.*?)<H1>(.*?)</H1> <TITLE>\2</TITLE>\1<H1>\2</H1> Update HTML title tags (<TITLE>.*?</TITLE>|(</HEAD>))(.*?)<H1>(.*?)</H1> <TITLE>\4</TITLE>\2\3<H1>\4</H1> Update or insert HTML title tags <BODY[^>]*> <BODY BGCOLOR=white TEXT=black> Replace HTML tags This example replaces all body tags, regardless of their attributes, with another body tag with the attributes in the replacement. This is a quick way to make web sites consistent. bgcolor=([_a-z0-9]+|'[^\\']*'|"[^\\"]*") bgcolor=blue <table[^>]*> Replace HTML attributes This example replaces bgcolor attributes in table tags <TITLE>(.*?)</TITLE> # \1 if ('%FILENAME%' == $mainpage) { print '<B>\1</B><BR>'; } else { print '<A HREF="%FILENAME%">\1</A><BR>'; } Generate a PHP navigation bar Mark some HTML or PHP files in the File Selector to generate PHP code for a simple navigation bar that can later be referenced by all web pages. </h1> \0 <? requires('navbar.php'); navbar('%FILENAME%'); ?> Include a PHP navigation bar After generating a navigation bar, execute this action on the same files to make them reference the navigation bar. \A \z header text footer text Add a header and footer to files ^(?<client>\S+)\s+(?<auth>\S+\s+\S+)\s+\[(?<datetime>[^]]+)\]\s+"(?:GET|POST|HEAD) (?<file>[^ ?"]+)\??(?<parameters>[^ ?"]+)? HTTP/[0-9.]+"\s+(?<status>[0-9]+)\s+(?<size>[-0-9]+)\s+"(?<referrer>[^"]*)"\s+"(?<useragent>[^"]*)"$ ${referrer} Inspect Apache web logs This example captures each part of each log entry into a named capturing group. Adjust the regular expression and the backreference in the data to be collected to extract the information you are looking for. ^(?<client>\S+)\s+(?<auth>\S+\s+\S+)\s+\[(?<datetime>[^]]+)\]\s+"GET (?<file>[^ ?"]+?\.html?)\??(?<parameters>[^ ?"]+)? HTTP/[0-9.]+"\s+(?<status>[0-9]+)\s+(?<size>[-0-9]+)\s+"(?<referrer>[^"]*)"\s+"(?<useragent>[^"]*)"$ ${referrer} Inspect Apache web logs - Page hits only This example captures each part of log entries concerning page hits into a named capturing group. Hits to images and other files are ignored. Adjust the regular expression and the backreference in the data to be collected to extract the information you are looking for. c:\\My Documents([^\t\r\n<>|/:"]*[^\s<>|/:"]) /home/me\1 ; = \=/; =_ Convert Windows paths into UNIX paths Changes paths under c:\My Documents\ into /home/me/ Extra processing is used to replace backslashes with forward slashes, and spaces with underscores <TITLE>(.*?)</TITLE> <!--\1--> <P><A HREF="%FILENAME%">\1</A></P> Indexing HTML files <TITLE>(.*?)</TITLE>.*?<P[^>]+>(.*?)</P> <!--\1--> <P><A HREF="%FILENAME%">\1</A></P> <UL>\2</UL> Indexing HTML files with first paragraph \d+ ${headerlevel} <h(?'headerlevel'[1-6])>(?'tag'.*?)</h\k'headerlevel'> ${tag} Make numbers in HTML heading tags consistent See "how to make sections and their contents consistent" in the help file for an explanation of this action. \b[1-6]\b <h\0>${tag}</h\0> <h(?'headerlevel'[1-6])>(?'tag'.*?)</h\k'headerlevel'> Make HTML heading tags consistent with their contents See "how to make sections and their contents consistent" in the help file for an explanation of this action. Enter your search terms here //.* (?s)/\*.*?\*/ "[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*" '(?:[^'\\]|\\.)' Source code, Java or C/C++, search through comments and strings Enter your search terms here //.* (?s)/\*.*?\*/ "[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*" '(?:[^'\\]|\\.)' Source code, Java or C/C++, do not search through comments or strings Enter your search terms here //.* (?s)/\*.*?\*/ "[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*" '(?:[^'\\]|\\.)' \0 \0 Source code, Java or C/C++, search through comments only IMPORTANT: Do NOT disable the string regular expression in the list. It prevents comment characters inside strings from being misinterpreted. Use "section collect" to skip strings when searching. Enter your search terms here //.* (?s)/\*.*?\*/ "[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*" '(?:[^'\\]|\\.)' \0 Source code, Java or C/C++, search through strings only IMPORTANT: Do NOT disable the comment regular expressions in the list. It prevents quote characters inside comments from being misinterpreted. Use "section collect" to skip comments when searching. "GET /([-_a-z0-9]+\.html)? HTTP/[0-9.]+"\s+[0-9]+\s+[-0-9]+\s+"(?:http://www\.google\.(?:com?\.)?[a-z]{2,3}/search\?.*?q=\+*+([^&"\r\n]++)[^"\r\n]*)" \l2 = += %20= %22=" %23=# %24=$ %27=' %28=( %29=) %2B=+ %2E=. %3B=; Inspect Apache web logs - Google search terms The main action matches each line in an Apache web log that logs a hit to an HTML file or the home page (/) with a Google search results page as the referrer. The action collects the search terms that produced the search results. The extra processing converts the most common URL-encoded characters into regular characters to make the keywords readable. "GET /([-_a-z0-9]+\.html)? HTTP/[0-9.]+"\s+[0-9]+\s+[-0-9]+\s+"(?:http://www\.google\.(?:com?\.)?[a-z]{2,3}/search\?.*?q=\+*+([^&"\r\n]++)[^"\r\n]*)" \l2 -> \1 = += %20= %22=" %23=# %24=$ %27=' %28=( %29=) %2B=+ %2E=. %3B=; Inspect Apache web logs - Google search terms with landing pages The main action matches each line in an Apache web log that logs a hit to an HTML file or the home page (/) with a Google search results page as the referrer. The action collects the search terms that produced the search results. The extra processing converts the most common URL-encoded characters into regular characters to make the keywords readable. (\w+)\s+(?=(\w+)) \1 \2 Find word pairs (\w+)\s+(?=(\w+)\s+(\w+)) \1 \2 \3 Find word triplets \b(\w+)(\s+\1\b)+ Find repeated words \b(\w+)(\s+\1\b)+ \1 Delete repeated words "GET (?<file>[^ ?"]+?\.html?)\??(?<parameters>[^ ?"]+)? HTTP/[0-9.]+"\s+[0-9]+\s+[-0-9]+\s+"(?:-|http://(?<referrer>[-.a-z0-9]+)[^"]*)" ${referrer} Inspect Apache web logs - Referring domains Matches log entries concerning page hits only. The file and referring domain are captured. The regex for matching complete log file entries was clipped at the start and the end to produce this example. By removing the parts we aren't interested in, we speed up the action. "GET [^ ?"]+?\.html?[^ "]* HTTP/[0-9.]+"\s+[0-9]+\s+[-0-9]+\s+"(?<referrer>[^"]*)" ${referrer} Inspect Apache web logs - Referring URLs Matches log entries concerning page hits only. The file and referring URL are captured. The regex for matching complete log file entries was clipped at the start and the end to produce this example. By removing the parts we aren't interested in, we speed up the action. ^([^=;\r\n]+)=.*$ ${header}/\1 ^\s*\[(?'header'[^]\r\n]+)](?:\r\n\s*+[^[].*+)+ Collect header/item pairs from .ini files \b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}\b <a href="[^>"]+" Find email addresses in HTML anchors enter your search term here Collect lines containing a search term Complete lines are collected. Set the "target file creation" options to save the collected lines into a file. enter your search term here Delete lines containing a search term first search term second search term Delete lines containing all search terms first search term second search term Collect lines containing all search terms Complete lines are collected. Set the "target file creation" options to save the collected lines into a file. Deliver to:\r\n(.*)\r\n(.*)\r\n(?:(.*)\r\n)?(.*?)[, ]+([A-Z]{2})[, ]+([0-9]{5}(?:-[0-9]{4})) \1,\2,\3,\4,\5,\6 Extract data into a CSV file or spreadsheet This example matches delivery addresses in the following format: Deliver to: Joe N. Doe Street address (one or two lines) City, ST, 12345-6789 It adds them to the CSV file as: name,address 1,address 2,city,state,zip first search term second search term List files containing all search terms word1 word2 word3 Find two or more words on the same line Find all matches of "word1", "word2" and "word3", but only on those lines where all three words can be found. This is done with the "list only sections matching all items" option. \bword1\W+(?:\w+\W+){1,6}word2\b Find two words near each other (ordered) Find word1 and word2, in that order, separated by at least 1 and at most 6 words. \b(?:word1\W+(?:\w+\W+){1,6}word2|word2\W+(?:\w+\W+){1,6}word1)\b Find two words near each other (unordered) Find word1 and word2, or vice versa, separated by at least 1 and at most 6 words. Enter your search terms here //.* (?s)/\*.*?\*/ "[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*" '(?:[^'\\]|\\.)' (?s)[^"'/]++(?:/(?![/*])[^"'/]*+)* \0 \0 \0 Source code, Java or C/C++, do not search through comments Sectioning regexes 3 and 4 are needed to make sure // and /* characters inside strings are not interpreted as comments. Sectioning regex 5 matches anything up to the next comment or string. This regex is needed because we're using the "search and collect sections" file sectioning type. PowerGREP currently does not have a sectioning type like "split along delimiters" that allows you to split along only certain regex matches in the way that "search and collect sections" allows you to search through only certain regex matches.