Home >  Products >  Compare It! 3 >  Online Help
Welcome to Compare It!
About Compare It!
Installing and Removing Compare It!
What's New in This release?
Quick Start
User Interface Basics
Application Window Illustration
Using Compare It!
Comparing files
Merging Files
Editing Files
Setting Options
File Filters
Advanced Comparison
Printing and Reporting
Print options
Print Options: Margins
Print Options: Advanced
Comparison report
Comparison statistics
Keyboard Shortcuts, Toolbar Buttons, Menu Commands
Advanced Functions
Adding Shortcuts to External Applications
Adaptive comparison
Auto Backup
Automatch rules
Command Line Usage
Configuration File
Changes Only Mode
Custom Syntax Files
Defining Column Ranges
Enhanced Open File
File lists support
Folders comparison
Ignore Difference
Manual Matching
Merged Report
Moved Sections
Partial matching
Result File Support
Unicode Support
Using Compare It! with File Manager
Using fixed/alternative font
Using Regular Expressions
Using RegExps substrings
Word files comparison
Excel files comparison
Other file formats support
Zip File Support
General Information
What is Shareware?
How To Register
Warranty and License
Future Releases
Other Products
Frequently Asked Questions
Updates and Support
RegExp substrings replacements Regular Expressions Compare doc files

Regular expressions give you an ability to make complex search queries. However when it comes to replace operation, you may feel limited in abilities, since you are required to replace this complex search expression with simple text. This is where substrings come to help you.


Instead of reading boring theory, let's work with typical comparison problem. Suppose we have original document with multiple dates in this format: September 12, 2003; September 25, 2002 etc. (For simplicity we will work only with September in this example). Your colleague has made some changes and, among others, changed date format to read as 12.09.2003; 25.09.2002.
So here is a problem for us - ignore date format change.
Our first approach could be very simple - replace all dates to empty string, we can do this by using "September \d{1,2},\d{4}" regexp. However in this case we will miss changes made to the date itself. What we need is to combine replace string from matched parts of search expression, i.e. from substrings.

Step 1: Mark substrings
To mark substring in search expression, we use parenthesis: "September (\d{1,2}),(\d{4})". Substrings are numbered 1,2,... as they appear in original expression. In our case if string September 12, 2003 will be matched, substring #1 = "12", substring #2 = "2003".

Step 2: Use substrings
To insert found substrings in replacement string, use $1, $2,... variables. Summarizing all this information, here is search/replace expressions to ignore date format change:
Search: September (\d{1,2}),(\d{4})
Replace: $1.09.$2

Where can I use it?

You can use this approach in both cases, when RegExps are used for replacement in Compare It!:
© 1996-2009, Grig Software, All Rights Reserved Regular Expressions Compare doc files
Browser Based Help. Published by chm2web software.