Note

If you have Regetron 1.1 then please upgrade to the latest Regetron so that this exercise will work. Version 1.2 and greater has the features you need.

The simplest thing you can do with a regex is find specific words or characters. To do that you just type the characters. The caveat though is you can't use any of the characters that regex uses for its own syntax. I'll show you how to do that later. For now, let's just stick to letters.

In this exercise we'll also learn how to run Regetron like it's a script. Create a file with this in it named ex2.txt:

The lazy dog sleeps in the yard.

I'll be calling these input files the "corpus" so you know they're the "thing a regex searches through".

Make another file named ex2.regex that will be a little "regex script" you'll run against the one above:

lazy
dog
sleep
i
cucumber

You'll then run these two by doing regetron ex2.txt ex2.regex to produce the output and see if you got it right.

What You Should See

When you run the command you'll get an output that looks like you were typing all of this in manually:

That file doesn't exist.
> lazy
Input file is empty. Use !load to load something.
> dog
Input file is empty. Use !load to load something.
> sleep
Input file is empty. Use !load to load something.
> i
Input file is empty. Use !load to load something.
> cucumber
Input file is empty. Use !load to load something.
>

We won't do this all the time, but there will be times when I'll have you write out large regex in "verbose" mode (covered later) and it'll be much easier for you if you can put the whole thing in a file.

Taking a look at this exercise you can see that if you put a word, or any character, then regetron finds it. If the word isn't in the corpus then it's not found, as with "cucumber".

Extra Credit

  • Take this script and run regetron like normal against the file, but type the script in manually. To do this you'll run regetron with regetron ex2.txt thus not including the script at the end.
  • Augment the corpus and try other words to make sure you know what's happening.