ANN: pyregex 0.5 - command line tools for Python's regular expression

aurora00 at gmail.com aurora00 at gmail.com
Fri Mar 10 03:07:17 CET 2006


pyregex is a command line tools for constructing and testing Python's
regular expression. Features includes text highlighting, detail break
down of match groups, substitution and a syntax quick reference. It is
released in the public domain.

Screenshot and download from
http://tungwaiyip.info/software/pyregex.html.

Wai Yip Tung

------------------------------------------------------------------------
Usage: pyregex.py [options] "-"|filename regex [replacement [count]]

Test Python regular expressions. Specify test data's filename or use
"-"
to enter test text from console. Optionally specify a replacement text.

Options:
-f      filter mode
-n nnn  limit to examine the first nnn lines. default no limit.
-m      show only matched line. default False


Regular Expression Syntax

Special Characters
------------------------------------------------------------------------
.       matches any character except a newline
^       matches the start of the string
$       matches the end of the string or just before the newline at the
end of
        the string
*       matches 0 or more repetitions of the preceding RE
+       matches 1 or more repetitions of the preceding RE
?       matches 0 or 1 repetitions of the preceding RE
{m}     exactly m copies of the previous RE should be matched
{m,n}   matches from m to n repetitions of the preceding RE
\       either escapes special characters or signals a special sequence
[]      indicate a set of characters. Characters can be listed
individually,
        or a range of characters can be indicated by giving two
characters and
        separating them by a "-". Special characters are not active
inside sets
        Including a "^" as the first character match the complement of
the set
|       A|B matches either A or B
(...)   indicates the start and end of a group
(?...)  this is an extension notation. See documentation for detail
(?iLmsux) I ignorecase; L locale; M multiline; S dotall; U unicode; X
verbose

*, +, ? and {m,n} are greedy. Append the ? qualifier to match
non-greedily.


Special Sequences
------------------------------------------------------------------------
\number matches the contents of the group of the same number. Groups
are
        numbered starting from 1
\A      matches only at the start of the string
\b      matches the empty string at the beginning or end of a word
\B      matches the empty string not at the beginning or end of a word
\d      matches any decimal digit
\D      matches any non-digit character
\g<name>use the substring matched by the group named 'name' for sub()
\s      matches any whitespace character
\S      matches any non-whitespace character
\w      matches any alphanumeric character and the underscore
\W      matches any non-alphanumeric character
\Z      matches only at the end of the string


See the Python documentation on Regular Expression Syntax for more
detail

http://docs.python.org/lib/re-syntax.html




More information about the Python-list mailing list