Review of Aba Search and Replace with video
20 Apr 2012
FindMySoft, a software download directory, published a Quick Look Video showcasing Aba Search and Replace 2.2 interface and features. You can watch the video and read a review of my program at their site.
Some clarifications to their review. Aba cannot search and replace in MS Word documents (yet!). About being “too simple for advanced users”: Aba’s support for regular expressions includes variable-length lookbehind and Unicode character classes; most search-and-replace tools lack these features. Generally, I try to keep the interface clean and less cluttered than competitors while adding advanced features for power users.
Aba 2.2 released
4 Jan 2012
The new version adds lookaround and braces in regular expressions. I also implemented \b anchor and non-capturing groups.
Several bugs were fixed including incorrect PHP syntax highlight, crash when processing invalid UTF-8 or when changing a long replacement.
Many thanks to Stefan Schuck for updating the German translation. I'm looking for people who can translate Aba into other languages (especially, French and Spanish).
Discount on Aba Search and Replace
20 Dec 2011
I would like to offer everybody 15% discount on Aba Search and Replace until the end of January. Please use the coupon code:
Happy2012
Future upgrades will be free for registered users. Thank you for using Aba. Happy Holidays and best wishes for the New Year!
Using search and replace to rename a method
5 Dec 2011
It's easy to rename a method using Aba Search and Replace:
- enter the current and the new names,
- turn on the Match whole word and Match case modes,
- review the found occurrences;
- press the Replace button.
The name of a method, GetFileSize, collided with the name of a Win32 API function, so I wanted to replace it with GetSize. The later is also shorter and avoids the tautology: file.GetFileSize.
To find the references to my method, not to the Win32 API function, I added a dot (and -> in C++): .GetFileSize
In a PHP code, I replaced all calls to addslashes with sqlite_escape_string when porting my site to SQLite. The two functions escape quotes differently; addslashes should never be used in SQLite.
Cleaning the output of a converter
18 Nov 2011
When I worked at a small web design company, we often had clients bringing us a MS Word, Excel, or PDF file that must be published on web. Not as a downloadable file, but as a web page integrated into their site.
Microsoft Word certainly can save files in HTML, but the resulting code was bloated and different from our design. What we needed was a simple HTML that our designer could edit and style. How could Aba S&R help us?
Here is a DOC file saved in HTML:
<h3 align=center style='text-align:center;'><b><span style='font-size:10.0pt;font-family:"Arial";'>Lorem ipsum</span></b></h3>
<p class=Normal align=justify style='text-indent:14.0pt;text-align:justify;'><span style='font-family:"Times New Roman";'>Lorem ipsum dolor sit <i>amet,</i> consectetur adipisicing elit.</span></p>
We need to remove all attributes and <span> tags:
<h3><b>Lorem ipsum</b></h3>
<p>Lorem ipsum dolor sit <i>amet,</i> consectetur adipisicing elit.</p>
The following replacements can be used:
Search for: <(p|h1|h2|h3) [^>]*> Replace with: <\1> Search for: <span [^>]*> Replace with: (nothing) Search for: </span> Replace with: (nothing)
[^>]* matches everything up to the next closing angle bracket >, and \1 means the text inside the first parentheses (in our case, the tag name).

Generally, I often used Aba to clean the output of a converter. For one client, I had to convert dozens of PDF files with technical specifications to HTML. There was a lot of formatting (subscripts, superscripts, tables), so I could not simply copy-and-paste it. There also were errors, for example, the letter O instead of zero in subscripts. Without Aba, I would not clean this mess.
Is it a bad practice?
Two redditors criticized my previous post about using regular expressions to replace HTML tags.
I fully agree that regexes should never be used to parse an arbitrary HTML code, for example, an HTML code entered by user. Never do this in your scripts; it's unreliable and insecure.
But what if you need to replace all relative links (/blog/) in your own code with absolute links (http://www.example.com/blog/), because you are moving some parts of your site to a subdomain (http://myproduct.example.com). Would you craft a script that parses your HTML code (carefully skipping <?php tags — Python's HTMLParser cannot do that), searches for all <a> tags with the href attribute, replaces the links, and saves the result to a file?
Or would you toss off a regex in a search-and-replace tool?

Aba 2.1 released
11 Nov 2011
The new version fixes some bugs like incorrectly displayed date/time and adds the File menu for viewing/editing a file or copying the results list into clipboard.
Just as always, the upgrade is free for registered users.
How to replace HTML tags using regular expressions
3 Nov 2011
Strictly speaking, you cannot parse HTML using only regular expressions. The reason is explained in any computer science curriculum: HTML is a context-free language, but regular expressions allow only regular languages. So, you cannot match nested tags with them.
However, regexes are really useful for quick search and replace in your web pages. Full parsing is unnecessary, because you know the HTML code that you wrote. Approaches that are “impure” from theoretical point of view work extremely well in this setting. You even can simplify the regexes shown below: say, if you never insert newlines between a and href, then you need not to allow for them in your regular expression.
Match an HTML tag
<a\s(.*?)>(.*?)</a>
This regex matches an <a> tag with any attributes. If you break it into parts:
\smatches a space or a newline aftera;.*?matches any text to the next closing angle bracket>;- another
.*?matches any text inside the tag.
Parenthesis are used to capture the attributes and the text inside tag. You can then refer to them using \1 and \2 in the replacement. For example, you can remove all links:

As mentioned above, the regex will not correctly match nested <a> tags; it just finds the next closing tag of the same type. But in this case, it's not important, because the nested <a> tags make little sense :)
Match an opening HTML tag with some attribute
<a\s([^>]*\s)?href="(.*?)"(.*?)>
This regex matches an opening <a> tag with href attribute. The differences from the previous example are:
[^>]*matches anything except the closing angle bracket>(so it skips any attributes beforehref);- the question mark
?makes the other attributes optional, sohrefcan immediately followa.
This regex is simple enough and works in most cases. The HTML standard allows spaces around = and single quotes instead of double quotes in attribute values. If you need to match such tags, you need a more complicated regex:
<a\s([^>]*\s)?href\s*=\s*(["'])(.*?)\2(.*?)>
But simpler regexes usually suffice. Here is how you can replace absolute links with relative ones:
![Search for <a\s([^>]*\s)?href="http://www.abareplace.com(.*?)" and replace with <a \1 href="\2"](/blog_html_tags2.png)
I hope that this short tutorial convinced you of the power of regular expressions :)
See also: Regular expression reference
Video trailer for Aba
27 Oct 2011
Softoxi, an independent software site, published an original review of Aba Search and Replace. They even shoot a video showing major features.
Another popular site, Softpedia, granted “100% clean” award to Aba, which means it does not contain any form of spyware or viruses.
Aba 2.0 released
25 Oct 2011

After a month of beta testing, I released Aba 2.0. The new features in this version include:
- Added syntax highlight for context viewer and for regular expressions.
- Implemented search history and favorites.
- Now you can undo a replacement if you have started another search or closed the program (undo information is saved in a dedicated folder).
- An editor or a viewer can be called for the selected file.
- When search or replacement is finished, the program notifies you by playing a sound.
- Visual styles and Windows 7 taskbar are now supported.
- When you edit the Replace with field, the search is not restarted (except when needed).
- Non-greedy matches are faster than they were in the previous version.
Many thanks to the beta testers: Kyle Alons, Massimiliano Tiraboschi, and JJS. Without your help, I would never find some tricky bugs :)
Unfortunately, German and Italian translations are still unfinished, but I'm waiting for response from our translators.
This is a blog about Aba Search and Replace, a tool for replacing text in multiple files.

