Skip to content

Sean1708/Regetron3.0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

THIS IS A FORK OF THE ORIGINAL REGETRON FOR USE WITH PYTHON 3.
EVERYTHONG SHOULD WORK THE SAME.
                    _____
                ___/  |  \___
             __/      |      \__
          __/         |         \__
         /|           |           |\
        | |           |           | |
        | |           |           | |
       |  |           |           |  |
       |  |        ___|___        |  |
      /   |    ___/  ___  \___    |   \
      |   |___/  ___/| |\___  \___|   |
      |   /   __/_ \_| |_/ _\__   \   |
     |   |___/\_  \_______/  _/\___|   |
    /   /___/   \___\___/___/   \___\   \
   /    |   |       |   |       |   |    \
  /     |   |_      |   |      _|   |     \
 |___   |___|_\   _/|___|\_   /_|___|   ___|
 |_  \    |   |\ /  |___|  \ /|   |    /  _|
 ||| |    |   | |  _______  | |   |    | |||
 ||| |    |   | |  \_____/  | |   |    | |||
 ||| |    |   | |    ___    | |   |    | |||
 ||| |    |   | |           | |   |    | |||
 ||| |    |   | |           | |   |    | |||
 ||| |    |   | |           | |   |    | |||
 ||| |    |   |\|           |/|   |    | |||
 \||_|____|___|-\___________/-|___|____|_||/


Regetron The Regex Teaching Shell
=================================

Regetron is a simple shell for learning to use regular expressions.
It simply loads files you tell it to, then gives you a prompt for
entering regex and having it print the lines.  It's designed to
work with the book I'm making named "Learn Regex The Hard Way"
that I'm about to start working on.

Installation
============

It's in PyPI as regetron so just do:

  pip install regetron

Or, if you don't like that do:

  easy_install regetron

Or, if you don't like that, then check out the git repo at:

  https://gitorious.org/regetron/regetron

And figure it out for yourself.

Usage
=====

After that just run regetron like this:

  $ regetron 
  Regetron! The regex teaching shell.
  Type your regex at the prompt and hit enter. It'll show you the
  lines that match that regex, or nothing if nothing matches.
  Hit CTRL-d to quit (CTRL-z on windows).
  > 

Setting Data To Work On
=======================

At this point you can use some commands to setup some data
and then type regex to see how they work.  Try this:

  > !data "This is some stuff\nAnd some more stuff\n"
  > This
  0000: This is some stuff
  > stuff
  0000: This is some stuff
  0001: And some more stuff
  >

Commands start with ! and are one word then some args.  The !data
command takes any python expression, evals it, then cuts it up
with split.  Basically you can enter in your own python example
to try regex against.

Loading Files
=============

If you want to load a file, it's !load or pass the file on the
command line:

  > !load LICENSE
  > Zed
  0000: Copyright (c) 2011, Zed A. Shaw
  0013: * Neither the name of the Zed A. Shaw, "Learn Regex The Hard Way", nor the
  > 

That's me loading the LICENSE file for regetron.  You can also do that with:

  regetron LICENSE

Matching Vs. Searching Toggle
=============================

There's one more command !match which switches regetron from searching
for the regex in the lines to matching the line exactly:

  > !match
  Match mode: match
  > Zed
  > .*Zed.*
  0000: Copyright (c) 2011, Zed A. Shaw
  0013: * Neither the name of the Zed A. Shaw, "Learn Regex The Hard Way", nor the
  >

It works like a toggle so do it again and it goes back to search mode.

Verbose Regex For Commenting
==============================

You can enter verbose commented regex.  Just hit enter once,
then start typing, and end it with an empty line:

  > 
  (?i) # set to case insensitive
  ^ # starts with
  .* # any number of chars
  (zed|software) # zed or software
  .* # any chars
  $ # to the end
  
  0000: Copyright (c) 2011, Zed A. Shaw
  0013: * Neither the name of the Zed A. Shaw, "Learn Regex The Hard Way", nor the
  0015:   derived from this software without specific prior written permission.
  0017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  0026: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  >

Loading Regex From Files
========================

You can load verbose regex from files you have saved using the !parse command:

  > !parse example/sample.regex
  0000: Copyright (c) 2011, Zed A. Shaw
  0013: * Neither the name of the Zed A. Shaw, "Learn Regex The Hard Way", nor the
  0015:   derived from this software without specific prior written permission.
  0017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  0026: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

You can also give a whole "script" of input if you add an extra parameter:

  regetron sample.txt myscript.regex

Which will run the script of regex against the file sample.txt.  Here's
a test regex that I run against the regetron setup.py:

    [a-z]
    !load setup.py

    [ # start set
    a-z # a through z
    ] # end set
    edshaw # rest of my name

    !rep /zedshaw/XXXX/

Which is available in the examples directory of the source.

Search Replace
==============

You can use the !rep command to replace a regex with some text.  You use it
by giving a sed style search expression:

    !rep /zedshaw/XXX/

And the '/' characters can be any char, so you can also do:

    !rep |http://|XXX|

It does not actually edit any files or the input.  It just prints out
lines that matched, but with the replace done to them.  This is useful
for seeing what a regex will do.

Scrollback And Editing
======================

If you have readline support then you can get a full scrollback, history,
and can edit lines.


Quitting
========

You can quit regetron by hitting CTRL-D (or CTRL-Z on windows).

About

A fork of Regetron for use with Python 3.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •