One major problem with regular expressions is you need to sit down and manually translate them to and from English to understand them. Eventually this translation happens in your head, but in the beginning you'll want to do the work. Even after you've mastered "regex as a language" you'll still want to do this on large regular expressions.

To help you do this, there is a "verbose mode" to the Python regex system, and Regetron will let you write these out. Just hit enter at a prompt, and then type in the regex. When your done enter a blank line. Here's how you would rewrite Exercise 1 to use verbose mode:

!data "The lazy dog\nsleeps in the yard."

# exercise 1 .*lazy.*
.    # any character
*    # repeat, 0-or-more
lazy
.    # any character
*    # repeat, 0-or-more


# exercise 1 [A-Z][a-z]*
[    # start set
 A-Z  # A through Z
]    # end set
[    # then start set
 a-z  # a through z (lowercase)
]    # end set
*    # repeat 0-or-more


# exercise 1 [a-z]\.
[    # start set
 a-z # a through z
]    # end set
\.   # literal . char

The first thing you should notice is I can use comments to describe what each character does. The comment is after the '#' (octothorpe) character. You can also see that I can indent, as I do on lines 13 and 16, which helps understand the structure. I can do this because in verbose mode all space and comments are ignored. One more thing to understand is that to make verbose mode work in regetron you have to do an empty line to start a block, and then another to end it, so there's two empty lines between blocks.

What You Should See

When you run this you should get something like this:

That file doesn't exist.
> !data "The lazy dog\nsleeps in the yard."
>
# exercise 1 .*lazy.*
.    # any character
*    # repeat, 0-or-more
lazy
.    # any character
*    # repeat, 0-or-more

0000: The lazy dog
>
# exercise 1 [A-Z][a-z]*
[    # start set
 A-Z  # A through Z
]    # end set
[    # then start set
 a-z  # a through z (lowercase)
]    # end set
*    # repeat 0-or-more

0000: The lazy dog
0001: sleeps in the yard.
>
# exercise 1 [a-z]\.
[    # start set
 a-z # a through z
]    # end set
\.   # literal . char

0001: sleeps in the yard.
>

Keep in mind that this is a technique we'll use for manually learning the Regex language from here on, and for when you write complex regular expressions that you have to maintain. For simple regex like this you would just write them out normally.

Extra Credit

This extra credit is simple but tedious Write out all of the regex you've done so far (or as many as you can stomach) in verbose form. This will be tedious and annoying, but the translation process will make you learn these symbols well.

Portability Notes

Many regex engines do not have a verbose mode. Keep that in mind when you write them and check the documentation.