Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] EditPad(Lite) for Linux



When not using Linux, I use EditPadPro for 90% of my text based work, so
I'm quite happy to see that there is now a version for Linux.  It is a
beta version, and I haven't tested it yet (I just found out myself), but
I've been completely happy with the W-based version, so I assume this
will be also be great!  The following is from a newsletter from JGsoft:



JGsoft Newsletter  --  March 2003
=================================

Contents
========

1. Preview: EditPad Lite for Linux
2. Tips & Tricks: Multi-requirements regex matches


Preview: EditPad Lite for Linux
===============================

We have received plenty of requests for Linux versions of our popular 
text editors EditPad Lite and Pro.  Up till now, they were only 
available for Windows 95, 98, ME, NT4, 2000 and XP.

To test the Linux waters, we have ported EditPad Lite to Linux
("to port" is the technical term for making an application available on 
a new platform on which it was originally unavailable).  You can 
download the first beta or preview version of EditPad Lite for Linux 
from http://www.editpadlite.com/linux.html

EditPad Lite for Linux is designed to be as identical as possible to 
the Windows version.  Our goal is to provide a text editor that will 
make people moving from Windows to Linux feel at home on their new 
platform.  There are already many good text editors available for 
Linux, but most of them work quite differently from text editors on the 
Windows platform.

EditPad Lite for Linux should work fine on any Linux machine running a 
recent version of XFree, the standard windowing package under Linux.  
EditPad Lite for Linux depends on a special version of the QT library.  
This library is included with the full download of EditPad, so EditPad 
Lite will work fine if your system does not have QT installed, or if it 
uses a different version.  The library included with EditPad Lite has a 
different name than the standard QT libraries, so there should be no 
version conflicts.

EditPad Pro is not available for Linux at this time.  Since EditPad 
Lite is a subset of EditPad Pro, porting EditPad Lite to Linux is the 
first step in porting EditPad Pro.

Feel free to download a copy of EditPad Lite for Linux from 
http://www.editpadlite.com/linux.html  Installation instructions can be 
found on this web page as well.  After trying EditPad Lite for Linux, 
feel free to tell me about your experiences, positive and negative.  
This feedback will be very useful for porting EditPad Pro.



Tips & Tricks: Multi-requirements regex matches
===============================================

This month I will share another regular expression tip with you.  
Regular expressions are a pattern language that allow you to perform 
complex search (and replace) operations.  Both EditPad Pro and 
PowerGREP use Perl-compatible regular expressions, including an 
interesting new concept introduced by Perl 5: lookaround.

Lookaround is the collective term for lookahead and lookbehind, both 
available in a positive and a negative edition.  They are also called 
"zero-width assertions", because they do not "consume" any characters 
of the text searched through.  They only assert whether a particular 
regex can be matched at the current position, or not.

Lookahead searches forward.  The regex "a(?=b)" (without the double 
quotes) matches an a followed by a b.  The difference between this 
regex and plainly "ab" is that in the former regex, the "b" is not part 
of the text matched by the regex, while with the latter, it is.  This 
is because the lookahead (?=b) does not consume any characters.  

Using negative lookahead, the regex "a(?!b)" matches an "a" not 
followed by a "b".  This is very different from "a[^b]" which matches 
two characters: an "a", followed by any character except a b.  The 
former will match an "a" at the end of the file, but the latter will 
not, since at the end of the file, there is no non-b-character 
following the "a".

Lookbehind works similarly, but searches backwards.  "(?<=b)a" matches 
a "a" preceded by a "b".  "(?<!b)a" matches an a not preceded by a "b".

If you play with this a bit in the search function of EditPad Pro, the 
above should not be too difficult to grasp.  What is not so obvious 
from the above, is that using lookaround, you can apply two 
requirements to the same piece of text.

Suppose you want to find a word that is between 6 and 12 letters long, 
and contains the word "cat".  Without lookaround, you'd have to specify 
all possible permutations using alternation:  
"\b(cat\w{3}|\wcat\w{2}|\w{3}cat)\b" just for the 6-letter words.
This gets unwieldy.

For the first requirement, finding a word between 6 and 12 letters 
long, we can use the regex "\b\w{6,12}\b".  For the second, finding any 
word containing "cat", we can use "\b\w*cat\w*\b".  Easy enough if 
you've read the introduction to regular expressions included with 
EditPad Pro's and PowerGREP's documentation.

Combining those is just as easy when you understand that lookahead does 
not consume any characters: "(?=\b\w{6,12}\b)\b\w*cat\w*\b".  If you 
test this regex on this newsletter, it will find one such word.

The lookahead part "(?=\b\w{6,12}\b)" matches a word between 6 and 12 
letters long, but then discards that match, leaving only the starting 
position.  Only when the starting position of a 6 to 12-letter word has 
been found, is the remainder of the regex evaluated.  The first \b in 
the remainder is guaranteed to match, and the first \w* matches all the 
characters in the word.  The regex engine then backtracks (see EditPad 
Pro's and PowerGREP's docs) trying to match "cat".  If it can, the 
second \w* will match the remaining letters in the word, causing the 
entire word to be matched.  If it cannot, the entire regex fails and 
the software will continue searching at the next character in the file.

If you have more requirements, simply add more lookahead.  If we want 
to expand the above requirements to find a word (rather an identifier 
in a programming language) that also contains an underscore, we could 
use: "(?=\b\w{6,12}\b)(?=\w*cat)\w*_\w*".  I removed some of the \b's 
because they're guaranteed to match anyway, because of the first 
lookahead.

If an additional requirement is that the identifier should not contain 
the word "dog", the regex becomes: 
"(?=\b\w{6,12}\b)(?=\w*cat)(?!\w*dog)\w*_\w*"

As you can see, regular expressions allow you to perform powerful 
searches.  Together with backreferences (again, see the documentation), 
you can perform powerful search and replace operations.  If we rewrite 
the above regex to "(?=\b\w{6,12}\b)(?=(\w*)cat(\w*))(?!\w*dog)\w*_\w*" 
then we can replace "cat" with "mouse" by typing "\1mouse\2" in the 
replacement box.  Note that while lookaround does not consume 
characters, and does not contribute to the overall match, it does fill 
backreferences.

Kind regards,
Jan Goyvaerts.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links