PowerGREPPowerGREP

The Most Powerful Windows Grep Is The Easiest One to Use

More Power to Reduce Complexity

It may seem contradictory, but the most powerful Windows grep tool is also the easiest one to use, after a bit of practice. The reason is that you can execute many tasks in PowerGREP with several simple regular expressions, whereas a basic grep tool would require you to create one very complex regular expression to achieve the same result.

An example will make this clear. When searching through or modifying source code files, you'll often want to restrict the search to comments and/or strings, or search through comments and/or strings exclusively. E.g. if you discover you've been misspelling "referrer" as "referer" throughout your project, you'd probably want to fix the mistake in comments and strings, but leave the actual source code untouched. Modifying the source code might break ties to other modules, a hassle not worth correcting a spelling mistake. (As a bit of trivia: the Apache web server stores the referring URL in a variable HTTP_REFERER for exactly this reason.)

PowerGREP makes this easy with its "file sectioning" feature. Simply use stock regular expressions for matching comments and strings to section the file. Then use a plain text search-and-replace to substitute "referer" with "referrer". Quick and easy. You'll find this particular example in PowerGREP's grep library. In many other situations, you'll be able to use common regular expressions you'll find in libraries with tools like RegexBuddy or on various web sites.

      
Only US$ 159
Windows XP, Vista, 7, 8, 8.1, and 10
100% satisfied or money back
free trial download

Step by Step Example

  • Select "search for sections" from the "file sectioning" list in PowerGREP.
  • Set the section search type to "list of regular expressions".
  • Add one regular expression to the list for each kind of string and comment the programming language you're working with supports. E.g. for C or Java, use //.* for single-line comments, (?s)/\*.*?\*/ for multi-line comments, and "[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*" for strings.
  • Set the action type to "search and replace". Enter "referer" as the search text, and "referrer" as the replacement. Done!

Using a Single Regex (Don’t Try This at Home)

How hard can it be to do this with a traditional grep tool that uses only a single regular expression? It turns out it is neigh impossible. The closest solution I found is to search for this beast of a regex:

(//.*?)referer(.*)|("[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*)referer
([^"\\\r\n]*(?:\\.[^"\\\r\n]*)*")|(?s:(/\*.*?)referer(.*?\*/))

Since this regex matches much more than just the word "referer", we need to use \1\3\5referrer\2\4\6 as the replacement to reinsert everything that shouldn't be replaced. Unfortunately, this behemoth only replaces the first occurrence of "referer" in each comment or string. The simple solution using PowerGREP replaces all occurrences at once.

Don't make your life difficult by choosing a simple grep tool!

PowerGREP’s Action panel seems complex because of all the options it offers, but those options actually make things simple.
PowerGREP’s Action panel seems complex because of all the options it offers, but those options actually make things simple.

The Real Time Savings

Since PowerGREP enables you to use stock patterns in many situations, you can save a lot of time by saving your PowerGREP actions into a library. E.g. if the next day you want to extract email addresses from comments and strings, you'd use the same file sectioning settings. Instead of doing the search and replace, you'd search for a regex matching an email address, using a standard regular expression from a library, such as \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b.

With another Windows grep tool, where you only have a single regex at your disposal, you could try this monster:

//.*?(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b).*|
"[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*
(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b)
[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*"|
(?s:/\*.*?(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b).*?\*/)

You won't find something like this in any library. Too complicated.

Changing your mind is easy too. If you want to search through everything except comments or strings, or you want to search through either comments or strings only, you can use the same regular expression in PowerGREP. You just need to change a few options in the file sectioning. It only takes a few seconds.

But if you had to use one of the behemoth patterns above, you'd have to rewrite it completely.

See PowerGREP in Action

There are four ways to see PowerGREP in action:

Read more about PowerGREP's features and benefits.