|

Introduction
This is a simple Notepad replacement. The main feature is that you can Search and Replace optionally using regular expressions. The boost::regex library is used for regex support. Note that the intention is for the boost::regex library to eventually become part of the C++ Standard Library. Replace All is improved compared to normal Notepad, as it builds a new text file in memory and replaces the entire text at once when it has finished. This is much quicker than replacing every match in the edit window as you go along.
As the development of Notepad RE progresses, more sophisticated features are being added.
Features
- Find and Replace using regex - notepadreDoc.cpp
- Find and Replace in normal mode - notepadreDoc.cpp
- GREP/Find in Files capability - FindInFilesDlg.cpp
- Multiple Undo/Redo - notepadreView.cpp
- Dockable Find and Replace dialogs - MainFrm.cpp
- Find will wrap from bottom to top -- or top to bottom, depending on search direction -- if necessary - notepadreDoc.cpp
- If the file you are editing is changed by another process, you have the option of being asked if you want to reload - notepadreDoc.cpp
- Line and column displayed in status bar - MainFrm.cpp, called from notepadre.cpp
- You can drop files as path/filename from Explorer by clearing Options->Drop Files - MainFrm.cpp
- You can drag and drop text to and from the edit window to and from other applications that support drag and drop - notepadreView.cpp
- You can re-open an existing file, something that does not work in the standard
CEditView class - notepadre.cpp
- You can open a text file bigger than 1 MB - notepadreView.cpp
- Unicode is supported - notepadreFile.cpp
- You can open and re-save UNIX text files correctly - notepadreDoc.cpp
- The Find/Replace dialog is written from scratch - FindReplaceDlg.cp
- Help file included - MainFrm.cpp
What are Regular Expressions?
A Regular Expression is simply some text. I think it is safe to assume that anyone who has used a modern computer will have used Find and/or Replace dialogs in more than one application that allows text processing, whether it is Notepad, a word processing program, or a Web browser. At the simplest level, a regular expression is no different from the text you type into the edit field of a Find dialog. Where regular expressions differ from normal text is that they give special meaning to certain characters, allowing you to specify textual 'patterns' rather than just literal text. The special characters are the following:
'.', '|', '*', '?', '+', '(', ')', '{', '}', '[', ']', '^', '$' and '\'.
These characters are often known as 'metacharacters' in the jargon of regular expressions. If you have ever typed something like:
*.txt
or something similar, then you are already familiar with the concept of characters having special meaning in a piece (string) of text. Wildcards -- i.e. the characters '*' and '?' -- used when negotiating most computer file systems are a massively simplified version of regular expressions. As well as being able to match any character ('?') or any string ('*'), regular expressions allow you to specify ranges of characters that can match, repeating textual patterns, alternative matching patterns and even matching positions within text. Note that in the syntax of regular expressions, the wildcard character '?' becomes '.' and '*' becomes '.*'.
If you have never used regular expressions before, then once you have learned the syntax you are in for a pleasant surprise. Once you have mastered their use, you will never look back! The official reference for the boost regular expression library is here. See this Regular Expression Primer for a very basic description. The book Mastering Regular Expressions is very good for when you really want to get in-depth!
Getting the Boost library
Visit Boost.org to obtain the boost regular expressions library.
Building the Boost Library
These instructions are for building under Visual C++ version 6.0
- Download the ZIP file
- Unzip the contents to C:\
- From a command prompt:
- C:\>"C:\Program Files\Microsoft Visual Studio\VC98\Bin\vcvars32.bat"
- Ensure the environment variable 'include' includes the path "C:\Program Files\Microsoft Visual Studio\VC98\include"
- Ensure environment variable 'lib' includes the path "C:\Program Files\Microsoft Visual Studio\VC98\lib"
- C:\>cd C:\boost_1_35_0\libs\regex\build
- C:\boost_1_35_0\libs\regex\build\>nmake /f vc6.mak
- Wait until the build finishes (you might want to get a coffee..!)
- Add C:\boost_1_35_0 to your includes (Tools, Options, Directories, Include files from the VC menu)
- Add C:\boost_1_35_0\libs\regex\build\vc6 to your library path (Tools, Options, Directories, Library Files from the VC menu)
Getting the Microsoft HTML Help Workshop
Get it here.
Installing HTML Help
- Download htmlhelp.exe from the link above
- Run htmlhelp.exe, installing to the default directory C:\Program Files\HTML Help Workshop
- Add C:\Program Files\HTML Help Workshop\include to your includes (Tools, Options, Directories, Include files from the VC menu)
- Add C:\Program Files\HTML Help Workshop\lib to your library path (Tools, Options, Directories, Library Files from the VC menu)
Program Design
File Handling
Notepad RE supports ANSI, Unicode, Big Endian Unicode and UTF-8 file formats. Additionally, Windows, UNIX and Macintosh line endings are supported, including files with inconsistent line endings. The file handling routines are the most tricky parts of Notepad RE.
Regular Expression Syntax
The regular expression syntax is now selectable under the Options menu.
Matching, Including Over More Than One Line
I've aimed to provide default search functionality with the maximum amount of possibilities and the minimum amount of surprises. The basic aim is to provide functionality based on vi, but with several improvements.
- 'Char Classes' are supported (i.e.
[[:CLASS:]] syntax is allowed)
- 'Intervals' are supported (i.e.
{x,y} syntax allowed)
- 'Back References' are supported (i.e.
\1, \2 etc. are allowed)
- 'Escape in Lists' is supported (i.e. the
\ character is the escape character inside [...])
+ is supported (of course)
? is supported (of course)
| is supported (of course)
- Use Perl-like variables
$1, $2, $3 etc. in the Replace field to use captured text
.* matches characters on the current line, like vi. To continue a match to the next line, follow .* with \r\n
- Note that characters
\r and \n are treated as whitespace. For example, if you use \s+ as part of your regex, you may be surprised to find you have matched text across lines
$ works like it does in vi, but may also be followed by \r\n if you want to match the 'newline' character
References
- "The C++ Programming Language Special Edition" by Bjarne Stroustrup.
- "Advanced Windows" by Jeffrey Richter, Microsoft Press
- "The Essence of COM with ActiveX, a Programmer's Workbook" by David S. Platt, Prentice Hall
- "Mastering Regular Expressions" by Jeffrey E. F. Friedl, O'Reilly
- "Professional MFC with Visual C++ 6" by Mike Blaszczak, Wrox Press Inc
Future Work
- Popup menu in Replace dialog for regex replace syntax
- Investigate syntax highlighting
- Use the
std::tr1 interface to boost::regex
- Use Microsoft Unicode routines when loading/saving
- HEX view
This MFC version of Notepad RE will be improved until it is as close to Windows Notepad as possible. After that, I may rewrite it as a WTL program.
History
- 23 July, 2003
- 2 June, 2007: Version 1.1.0.1
- 4 June, 2007: Version 1.1.0.2
- BUG FIX: Replace with empty string works again!
- Group characters for undo
- Undoing all changes sets modified flag to
FALSE
- Replacing a selection now treated as an atomic undo/redo
- 10 June, 2007: Version 1.1.0.3
- BUG FIX: Clear Undo history when toggling word wrap
- 12 June, 2007: Version 1.1.0.4
- BUG FIX: Forgot to add the
OnKeyUp function!
- 14 June, 2007: Version 1.1.0.5
- 16 June, 2007: Version 1.1.0.6
- 17 June, 2007: Version 1.1.0.7
- Added first cut of Find in Files.
- 21 June, 2007: Version 1.1.0.8
- If Modified flag set before toggling word wrap -- therefore flushing the undo buffer -- don't set to
false if subsequently all edits are undone!
- Various tweaks to Find in Files
- 27 June, 2007: Version 1.1.0.9
- BUG FIX: A sequence of replacements is no longer treated as one big transaction by Undo.
- 3 July, 2007: Updated help file
- 4 July, 2007: Version 1.1.1.0
- Added popup menu to Find and Replace dialogs for regex syntax
- 6 July, 2007: Version 1.1.1.1
- BUG FIX: A sequence of replacements is no longer treated as one big transaction by Redo
- Finished popup menu in Find and Replace dialogs for regex syntax
- 10 July, 2007: Version 1.1.1.2
- Find in Files now sends output to a dockable toolbar.
- Changed tab order in Replace dialog.
- Changed 'Number' regex to be PERL mode friendly.
- 7 August, 2007: Version 1.1.1.3
- BUG FIX: Shift-Del only creates one Undo entry now!
- 8 August, 2007: Version 1.1.1.4
- BUG FIX: Ctrl-C Works again...
- 10 October, 2007: Version 1.1.1.5
- BUG FIX: Saving with word wrap enabled no longer saves too much text.
- Find in Files now runs in the background.
- 26 June, 2008: Version 1.1.1.6
- BUG FIX: Check for Non-Windows line endings in
CNotepadreFile::CountCharsUTF8() fixed
- Help file correction (thanks har0ld)
- Fixes to
CRegexSyntaxDlg
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 139 (Total in Forum: 139) (Refresh) | FirstPrevNext |
|
|
 |
|
|
First off thanks a lot this program was a blessing. I searched hours for a simple windows program that would have a regExp search/replace feature and that didn't need to be installed. At first I thought Notepad++ was the answer to my prayers but it's regExp support is a joke (only quantifiers are the greedy * and +, and multi line matches are virtually impossible to achieve without dirty workarounds). So once again THANK YOU A LOT.
I think I might have found a spelling-mistake in the chm help file ./Unicode_release/NotepadRE.chm in "Replace Syntax" it says:
\x{DDDD} Outputs the character whose hexadecimal code point is 0xDDDDD I'm not sure but I think there's one D too much at the end
ps:thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks for your feedback and I'm glad you found it useful! I have also found that most Windows editors have cruddy regex support (even Visual Studio). I also think the .NET so-called (i.e. non standard) regular expressions are worse than useless.
I will update the .chm.
Cheers,
Ben
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have released a new version of the RegEx Tester tool. You can download it free from http://www.codeproject.com/KB/string/regextester.aspx and http://sourceforge.net/projects/regextester
With RegEx Tester you can fully develop and test your regular expression against a target text. It's UI is designed to aid you in the RegEx developing. It uses and supports ALL of the features available in the .NET RegEx Class.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi!
Thanks for this! This notepad, is what I've been looking for, for about 10 years... When I was a child I knew an old guy who was working on an advanced editor which does the same (much more than this one, but basically the same), it was for DOS, and it was like the project of his life... It was capable of finding and replacing so complex expressions that I didnt know who the heck will ever need it. But it was his personal project, and as far as I know, he never shared it, or even published as software/shareware...
Your Notepad RE is going to save me soooo much headache!
Thanks again... Daniel
----- Daniel Cohen Gindi danielgindi (at) gmail dot com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Awesome job! It's easy to get used to, but if you can change the tab index so a tab from the find box jumps to replace instead of the regular expression drop down, it would feel more like the notepad find/replace.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks! Yes that's the way it works in VC and it makes sense, so I'll change it for the next version.
Cheers,
Ben
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
Because my library is for generating lexical analysers, whereas Notepad RE only needs a regular expression library.
boost::regex is officially part of C++ tr1 and will ultimately become part of the C++ Standard Library. It also has many more features than I could hope to include in a regex library.
I will be submitting lexertl to boost, as although it uses regexes the problem is solves is a different one. lexertl has already been successfully integrated into boost::spirit and boost::wave.
Regards,
Ben
|
| Sign In·View Thread·PermaLink | 4.40/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Hi, I have also created the similar text editor and named it "SoftPad". I will share it with you soon. I am currently enhancing some features in it.
Anurag Gandhi Bangalore, India.
Anurag Gandhi.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
... Watch out for 1.1.0.2 - I've fixed a bug where Replace with an empty string had stopped working! Here's the complete list of changes:
- BUG FIX: Replace with empty string works again! - Group characters for undo. - Undoing all changes sets modified flag to FALSE. - Replacing a selection now treated as an atomic undo/redo.
Cheers,
Ben
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello, i cant launch the project, i recive many errors! 48 errors all in the same file  error C2039: 'escape_in_lists' : is not a member of 'regbase' d:\boost_1_33_1\boost\regex\v4\regbase.hpp(32) : see declaration of 'regbase'
can someone explain me what is wrong! thanks in advance break
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
This sounds like a boost version problem to me. When 1.34 is released I will update notepadre (and switch to the TR1 regex interface).
Cheers,
Ben
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
Hello, thanx for answer, how to update Notepad RE? It's very important to me if i can use RE in my project!!! I use the last version of Regex from www.boost.org! What steps are you going?
regards break;
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Hello, is there any settings that i have to do before? When i try to run project i recive this error: htmlhelp.lib(init.obj) : error LNK2001: unresolved external symbol ___security_cookie htmlhelp.lib(init.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4 Unicode_Debug/notepadre.exe : fatal error LNK1120: 2 unresolved externals
The library htmlhelp.lib is on my computer already installed, and in its included in projectpaths under: tools->options->tab "directories" -> Show directories for -> Library files selected
with best regards termal
|
| Sign In·View Thread·PermaLink | 1.67/5 (3 votes) |
|
|
|
 |
|
|
When doing a regexp search using a character set the case of the characters is ignored regardless of whether the Match Case checkbox is ticked or not. Case is adhered to when searching using a regexp that does not use a character set.
For example: ^[a-z] will match lines starting with Fred or fred - and the same applies if I searched for ^[A-Z]. If I searched on ^f it would only match fred but not Fred - so that part works as expected.
The problem seems to occur regardless of what regexp syntax I use.
Is this a bug or is there a config option I need to set?
Thanks...Graeme
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
If memory serves, this is an annoying feature of the boost::regex 'collate' flag. Turn it off! (Options -> Regex Syntax...)
I have my regex options set to the following:
Main Syntax: Perl subset (no other flags set for Syntax Flags)
Match Flgs: not_dot_newline
All other flags are off.
Let me know if this works for you.
Cheers,
Ben
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Ben,
Thanks for getting back to me. You are correct. Turning off the 'collate' flag did the trick.
It's a nice little app. Thanks again.
...Graeme
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|