Article View: news.software.readers
Article #14279Draft description of trn regexp (Was: Re: rn/trn: Help! Where are the regexps documented?)
From: lvirden
Date: Wed, 04 Jan 1995 11:12
Date: Wed, 04 Jan 1995 11:12
156 lines
7880 bytes
7880 bytes
I am hoping to get email comments on the following document, which attempts
to describe the regular expressions supported by trn 3.6. I may see
your posted replies, but to be certain, email me as well.
I am sorry about the terminology, but it is patterned after the terminology
used in other Unix man pages to attempt some sort of consistency.
Draft description of TRN 3.6 regular expressions.
Date: 01/04/95
Author: Larry W. Virden and many Unix man page writers
Version: 0.01
TRN regular expressions:
A regular expression (RE) is a way of describing patterns which one wants to
use for searching. Most commonly these are used in the KILL file
to match articles for junking or selection for reading or passing on
to other programs.
One character REs are:
1. Anything other than the special characters about to be described
will result in a RE that matches itself.
2. A backslash (\) followed by any of the special character is
a one-character RE that matches the special character
itself. The special characters are:
a. ., *, [, and \ (period, asterisk, left square
bracket, and backslash, respectively), which
are always special, except when they appear
within square brackets ([]; see 1.4 below).
b. ^ (caret or circumflex), which is special at
the beginning of an entire RE (see 4.1 and 4.3
below), or when it immediately follows the left
of a pair of square brackets ([]) (see 1.4
below).
c. $ (dollar sign), which is special at the end of
an entire RE (see 4.2 below).
d. The slash is used to delimiate the entire RE.
1.3 A period (.) is a one-character RE that matches any
character except new-line.
1.4 A non-empty string of characters enclosed in square
brackets ([]) is a one-character RE that matches any
one character in that string. If, however, the first
character of the string is a circumflex (^), the
one-character RE matches any character except new-
line and the remaining characters in the string. The
^ has this special meaning only if it occurs first in
the string. The minus (-) may be used to indicate a
range of consecutive characters; for example, [0 - 9]
is equivalent to [0123456789]. The - loses this spe-
cial meaning if it occurs first (after an initial ^,
if any) or last in the string. The right square
bracket (]) does not terminate such a string when it
is the first character within it (after an initial ^,
if any); for example, []a-f] matches either a right
square bracket (]) or one of the ASCII letters a
through f inclusive. The four characters listed in
1.2.a above stand for themselves within such a string
of characters.
The following are the rules governing multiple character REs.
2.1 A one-character RE is a RE that matches whatever the
one-character RE matches.
2.2 A one-character RE followed by an asterisk (*) is a
RE that matches zero or more occurrences of the one-
character RE. If there is any choice, the longest
leftmost string that permits a match is chosen.
2.3 A one-character RE followed by \{m\}, \{m,\}, or
\{m,n\} is a RE that matches a range of occurrences
of the one-character RE. The values of m and n must
be non-negative integers less than 256; \{m\} matches
exactly m occurrences; \{m,\} matches at least m
occurrences; \{m,n\} matches any number of
occurrences between m and n inclusive. Whenever a
choice exists, the RE matches as many occurrences as
possible.
2.4 The concatenation of REs is a RE that matches the
concatenation of the strings matched by each com-
ponent of the RE.
2.5 A RE enclosed between the character sequences \( and
\) is a RE that matches whatever the unadorned RE
matches.
2.6 The expression \n matches the same string of characters
as was matched by an expression enclosed between \(
and \) earlier in the same RE. Here n is a single digit;
the sub-expression specified is that beginning with the
n-th occurrence of \( counting from the left. For
example, the expression ^\(.*\)\1$ matches a line
consisting of two repeated appearances of the same
string. Note that \0 matches whatever the last
\) matched.
A RE may be constrained to match words.
3.1 \b constrains a RE to match the beginning of a string
or to follow a character that is not a digit, under-
score, or letter. The first character matching the
RE must be a digit, underscore, or letter.
3.2 \B constrains a RE to match the beginning of a string
or to follow a character that is a digit, underscore,
or letter, and which is not the beginning of a string.
3.3 \w constrains a RE to match the beginning of a string
or to follow a character that is not a digit
or letter. The first character matching the
RE must be a digit or letter.
3.4 \W constrains a RE to match the beginning of a string
or to follow a character that is a digit
or letter and which is not the beginning of a string.
An entire RE may be constrained to match only an initial
segment or final segment of a line (or both).
4.1 A circumflex (^) at the beginning of an entire RE
constrains that RE to match an initial segment of a
line.
4.2 A dollar sign ($) at the end of an entire RE con-
strains that RE to match a final segment of a line.
4.3 The construction ^entire RE$ constrains the entire RE
to match the entire line.
You can express a series of REs.
5.1 Up to 10 alternatives may given in a pattern,
separated by \|, with the caveat that \( ... \| ... \)
is illegal.
Also, trn folds the case of REs by default, this can be overridden in
kill file processing by the c option.
--
:s Great net resources sought...
:s Larry W. Virden INET: larry.virden@cas.org
:s <URL:http://www-bprc.mps.ohio-state.edu/cgi-bin/hpp?lvirden_sig.html>
The task of an educator should be to irrigate the desert not clear the forest.
Technical Details
Message-ID:
<1995Jan4.111211.2967@chemabs.uucp>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!nntp.gmd.de!Germany.EU.net!howland.reston.ans.net!news.sprintlink.net!malgudi.oar.net!chemabs!lwv26References:
<1994Dec27.193413.4710@midway.uchicago.edu> <D1uyzA.2zo@borland.com>Show Full Headers
Complete Article Headers
Message-ID: <1995Jan4.111211.2967@chemabs.uucp> Subject: Draft description of trn regexp (Was: Re: rn/trn: Help! Where are the regexps documented?) Date: Wed, 4 Jan 1995 11:12:11 GMT From: lvirden@cas.org References: <1994Dec27.193413.4710@midway.uchicago.edu> <D1uyzA.2zo@borland.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!nntp.gmd.de!Germany.EU.net!howland.reston.ans.net!news.sprintlink.net!malgudi.oar.net!chemabs!lwv26 Newsgroups: news.software.readers Content-Type: text/plain; charset=US-ASCII Sender: lwv26@chemabs.uucp (Larry W. Virden) Reply-To: lvirden@cas.org Content-Transfer-Encoding: 7BIT Organization: Nedriv Software and Shoe Shiners, Uninc. Mime-Version: 1.0 Lines: 156