49
ii
32. Collect a List of Header and Item Pairs .................................................................................................................. 65
33. Collect Paragraphs (Split along Blank Lines) ......................................................................................................... 67
34. Apply an Extra Search-And-Replace to Target Files ............................................................................................ 68
35. Inspect Web Logs ....................................................................................................................................................... 69
36. Extract Google Search Terms from Web Logs ..................................................................................................... 71
37. Split Web Logs by Date ............................................................................................................................................. 72
38. Merge Web Logs by Date ......................................................................................................................................... 74
39. Split Logs into Files with a Certain Number of Entries ...................................................................................... 75
40. Split Database Dumps ............................................................................................................................................... 77
41. Compile Indices of Files ............................................................................................................................................ 79
42. Make Sections and Their Contents Consistent ...................................................................................................... 80
43. Generate a PHP Navigation Bar .............................................................................................................................. 82
44. Include a PHP Navigation Bar ................................................................................................................................. 84
PowerGREP Reference ....................................................................................... 85
1. PowerGREP Assistant ................................................................................................................................................. 87
2. File Selector Reference ................................................................................................................................................ 89
3. Import File Listings ...................................................................................................................................................... 94
4. File Selector Menu ........................................................................................................................................................ 96
5. Action Reference ........................................................................................................................................................ 103
6. Action Types ............................................................................................................................................................... 106
7. Search Terms and Options ....................................................................................................................................... 113
8. Action Part: Filter Files .............................................................................................................................................. 120
9. Action Part: File Sectioning ...................................................................................................................................... 123
10. Main Part of The Action ......................................................................................................................................... 128
11. Action Part: Extra Processing ................................................................................................................................ 130
12. Action Part: Context ................................................................................................................................................ 131
13. Action Part: Collect Between ................................................................................................................................. 134
14. Action Part: Target and Backup Files ................................................................................................................... 136
15. Action Parts and Named Capture .......................................................................................................................... 140
16. Action Menu.............................................................................................................................................................. 142
17. Sequence Reference.................................................................................................................................................. 146
18. Sequence Menu ......................................................................................................................................................... 149
19. Library Reference ..................................................................................................................................................... 154
20. Library Menu ............................................................................................................................................................. 156
21. Results Reference ..................................................................................................................................................... 158
22. Results Menu ............................................................................................................................................................. 161
23. Editor Reference ....................................................................................................................................................... 169
24. Editor Menu .............................................................................................................................................................. 172
25. Undo History Reference ......................................................................................................................................... 177
26. Undo History Menu ................................................................................................................................................. 179
27. Change PowerGREP’s Appearance ...................................................................................................................... 181
28. Share Experiences and Get Help on The User Forums .................................................................................... 185
29. Forum RSS Feeds ..................................................................................................................................................... 189
30. File Selector Preferences ......................................................................................................................................... 190
31. File Formats Preferences ......................................................................................................................................... 193
32. Archive Formats Preferences ................................................................................................................................. 198
33. Action Preferences ................................................................................................................................................... 202
34. Text Layout Configuration ..................................................................................................................................... 205
45
iii
35. Text Cursor Configuration...................................................................................................................................... 210
36. Text Encoding Preferences ..................................................................................................................................... 213
37. Results Preferences................................................................................................................................................... 217
38. Editor Preferences .................................................................................................................................................... 219
39. External Editors Preferences .................................................................................................................................. 222
40. General Preferences ................................................................................................................................................. 224
41. Color Configuration ................................................................................................................................................. 226
42. Match Placeholders .................................................................................................................................................. 230
43. Path Placeholders ..................................................................................................................................................... 239
44. Command Line Parameters .................................................................................................................................... 242
45. XML Format of PowerGREP Files ...................................................................................................................... 249
Regular Expression Tutorial ............................................................................. 251
1. Regular Expression Tutorial ..................................................................................................................................... 253
2. Regex Tutorial Table of Contents ............................................................................................................................ 255
3. Literal Characters ........................................................................................................................................................ 258
4. First Look at How a Regex Engine Works Internally .......................................................................................... 260
5. Character Classes or Character Sets......................................................................................................................... 262
6. The Dot Matches (Almost) Any Character ............................................................................................................ 266
7. Start of String and End of String Anchors ............................................................................................................. 268
8. Word Boundaries ........................................................................................................................................................ 272
9. Alternation with The Vertical Bar or Pipe Symbol ............................................................................................... 275
10. Optional Items .......................................................................................................................................................... 277
11. Repetition with Star and Plus ................................................................................................................................. 278
12. Use Round Brackets for Grouping ........................................................................................................................ 281
13. Named Capturing Groups ...................................................................................................................................... 286
14. Unicode Regular Expressions ................................................................................................................................. 288
15. Regex Matching Modes ........................................................................................................................................... 297
16. Possessive Quantifiers ............................................................................................................................................. 299
17. Atomic Grouping ..................................................................................................................................................... 302
18. Lookahead and Lookbehind Zero-Width Assertions ......................................................................................... 304
19. Testing The Same Part of a String for More Than One Requirement ............................................................ 308
20. Continuing at The End of The Previous Match.................................................................................................. 310
21. If-Then-Else Conditionals in Regular Expressions ............................................................................................ 312
22. XML Schema Character Classes ............................................................................................................................ 315
23. POSIX Bracket Expressions .................................................................................................................................. 317
24. Adding Comments to Regular Expressions ......................................................................................................... 321
25. Free-Spacing Regular Expressions ......................................................................................................................... 322
Regular Expression Examples .......................................................................... 323
1. Sample Regular Expressions ..................................................................................................................................... 325
2. Matching Floating Point Numbers with a Regular Expression .......................................................................... 328
3. How to Find or Validate an Email Address ........................................................................................................... 329
4. Matching a Valid Date ............................................................................................................................................... 332
5. Finding or Verifying Credit Card Numbers ........................................................................................................... 334
6. Matching Whole Lines of Text ................................................................................................................................. 336
13
iv
7. Deleting Duplicate Lines From a File ..................................................................................................................... 338
9. Find Two Words Near Each Other ........................................................................................................................ 340
10. Runaway Regular Expressions: Catastrophic Backtracking ............................................................................... 341
11. Repeating a Capturing Group vs. Capturing a Repeated Group ...................................................................... 347
12. Mixing Unicode and 8-bit Character Codes ......................................................................................................... 349
Regular Expression Reference .......................................................................... 351
1. Basic Syntax Reference .............................................................................................................................................. 353
2. Advanced Syntax Reference ...................................................................................................................................... 358
3. Unicode Syntax Reference ........................................................................................................................................ 362
4. Syntax Reference for Specific Regex Flavors ......................................................................................................... 363
5. Regular Expression Flavor Comparison ................................................................................................................. 365
6. Replacement Text Reference .................................................................................................................................... 376
2
Part 1
How to Use PowerGREP
32
3
1. Introducing PowerGREP
PowerGREP is a versatile and powerful text processing and search tool based on regular expressions. A
regular expression is a pattern that describes the form of a piece of text. E.g. a regular expression could match
a date or an email address. Any date or any email address that is, without specifying actual dates or actual email
addresses. Your search patterns can be as specific or as general as you want. This makes PowerGREP much
more flexible than a general search tool that only finds words and phrases (PowerGREP can do that too).
With PowerGREP you can use one or more such regular expressions to get lists of files, lists of search
matches in files, search-and-replace through files, rename files, merge files, split files, etc. First read the ´how
to use PowerGREPµ section to get a feel of the way PowerGREP works. Then check out the examples that
seem interesting to you. All examples include step-by-step instructions. The examples don’t require prior
experience with PowerGREP, but you’ll understand them better if you check out the ´how toµ section first.
Contents of This Manual
The PowerGREP manual consists of six parts:
1.
How to use PowerGREP: General, step-by-step instructions on how to use PowerGREP’s various
functionality. The most important options are explained.
2.
PowerGREP Examples: Step-by-step instructions explaining how to perform specific tasks with
PowerGREP. The examples cover most of PowerGREP’s functionality, giving you a good idea of
PowerGREP’s capabilities.
3.
PowerGREP Reference: Detailed information about all of PowerGREP’s capabilities. Each on-
screen control and each menu item is explained in detail. Also explains how to configure
PowerGREP, and sheds light on PowerGREP’s inner workings.
4.
Regular Expression Tutorial: Detailed tutorial on regular expressions. All aspects of regular
expressions are explained, from most common to most specialized.
5.
Regular Expression Examples: Examples illustrating how to build a regular expression from scratch.
6.
Regular Expression Reference: Brief reference of the various regular expression tokens.
34
4
2. Contact PowerGREP’s Developer and Publisher
PowerGREP is developed and published by Just Great Software Co. Ltd.
For the latest information on PowerGREP, please visit the official web site at http://www.powergrep.com/.
Before requesting technical support, please use the Check New Version command in the Help menu to see if
you are using the latest version of PowerGREP. We take pride in quickly fixing bugs and resolving problems
in free minor updates. If you encounter a problem with PowerGREP, it is quite possible that we have already
released a new version that no longer has this problem.
PowerGREP has a built-in Forum feature that allows you to easily communicate with other PowerGREP
users. If you’re having a technical problem with PowerGREP, you’re likely not the only one. The problem
may have already been discussed on the forums. So search there first and you may get an immediate answer.
If you don’t see your issue discussed, feel free to start a new conversation in the forum. Other PowerGREP
users will soon chime in, probably even before a Just Great Software technical support person sees it.
However, if you have purchased PowerGREP, you are entitled to free technical support via email. The
technical support only covers the installation and use of PowerGREP itself. In particular, technical support
does not cover learning and using regular expressions. The online forum does have a group devoted to
learning regular expressions though.
To request technical support, please use the Support and Feedback command in the Help menu. This
command will show some basic information about your computer and your copy of PowerGREP. Please
copy and paste this information into your email, as it will help us to respond more quickly to your inquiry. If
the problem is that you are unable to run PowerGREP, and thus cannot access the Support and Feedback
command, you can email support@powergrep.com. You can expect to receive a reply by the next business
day. For instant gratification, try the forums.
If you have any comments about PowerGREP, good or bad, suggestions for improvements, please do not
hesitate to send them to our technical support department. Or better yet: post them to the forum so other
PowerGREP users can add their vote. While we cannot implement each and every user wish, we do take all
feedback into account when developing new versions of our software. Customer feedback is an essential part
of Just Great Software.
Where to Buy (More Copies of) PowerGREP
To buy a single user or site license to PowerGREP, please visit http://www.powergrep.com/buynow.html
for a complete list of current purchasing options, and up to date pricing information. If you already have a
license but want to expand it to more users, please go to http://www.powergrep.com/multiuser.html. If you
have any questions about buying PowerGREP not answered on that page, please contact
sales@powergrep.com.
21
5
3. Getting Started with PowerGREP
I don’t exaggerate when I say that PowerGREP is the most powerful and versatile regular expression search
and text processing tool available worldwide today. But that doesn’t mean PowerGREP is complicated or
difficult to use. While it will certainly take some practice to get the most out of PowerGREP, this ´getting
startedµ section will show you PowerGREP is surprisingly convenient to use.
1. You start with telling PowerGREP which files you want to work with. Click on a file or folder in the File
Selector. Then select Include File or Folder in the File Selector menu to mark the file or folder to be searched
through. Marking a folder is a quick way to work with all the files in that folder. Later I will show you how
you can search through only certain files in a folder without marking them individually.
2. Then, you tell what PowerGREP should do with those files, by by defining an action on the Action panel.
For a simple search, select “simple search” in the drop-down list labeled ´action typeµ at the top of the
Action panel. For a search-and-replace, select “search-and-replace” in the ´action typeµ list. If you just
want to search for some text, select ´literal textµ as the ´search typeµ. Enter the text you want to find in the
search box.
3. Click the Preview button in the toolbar to start the search.
4. Inspect the search results on the Results panel. Double-click on a match to open the file in the editor and
see its context. If you’ve previewed or executed a search-and-replace, you can make or revert some or all
replacements via the Results and Editors menus or toolbars.
That’s all it takes! PowerGREP’s power and complexity remain hidden when you don’t need it, making
PowerGREP surprisingly easy to use.
Documents you may be interested
Documents you may be interested