![]()
| The Most Powerful Windows Grep Is The Easiest One to UseMore 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. Step by Step Example
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 (//.*?)referer(.*)| Don't make your life difficult by choosing a simple grep tool! The Real Time SavingsSince 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,4}\b. With another Windows grep tool, where you only have a single regex at your disposal, you could try: //.*?(\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}\b).*| 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 ActionThere are four ways to see PowerGREP in action:
Read more about PowerGREP's features and benefits.
| |||
|