Examples of Spanning Characters

Examples of Spanning Characters

==> egrep ' [^aeiou][aeiou]\{2\}[^aeiou] ' fortunes

Love the Sea? I dote upon it - from the beach

Now is the time for all good men to come to the aid of their country.

Nudists are people who wear one-button suits.

Old programmers never die. They just branch to a new address.

On a clear disk you can seek forever.

Satire doesn't look pretty upon a tombstone.

No one can feel as helpless as the owner of a sick goldfish.

The rain in Portugal falls mainly in the mountains.

The rain in Spain falls mainly in the plain.

==> egrep " [aeiou][^aeiou' ]\{3,\}" fortunes

Old programmers never die. They just branch to a new address.

==> egrep " [aeiou][^aeiou ]\{3,\}" fortunes

Old programmers never die. They just branch to a new address.

The future isn't what it used to be!

==> egrep ' X[UNI].$' fortunes

==>

==> egrep ' X[UNI]\{1,3\}.$ ' fortunes

Remember, UNIX spelled backwards is XINU.

Previous slide Next slide Back to the first slide View Graphic Version

Notes:

In the first example demonstrates matching a subexpression exactly a certain amount of times. The expression defined is as follows:

As a result lines 18, 21, 22, 23, 25, 28, 29, 30, and 31 satisfies matching this regular expression. The matches are underlined!

In the first part of the second example, the expression wants to:

Notice that line 23 satisfies this match. In the second part, the apostrophe was eliminated from the single character negation list (which means not to match a lowercase vowel). This is why line 24 now satisfies the match since the word isn’t satisfies the definition.

In the final example, the first expression says to match a space; then a capital X; a single character that can be an uppercase U, N, or I; followed by any

This expression failed! However, when we modify the subexpression for the U, N, or I to occur at least once, not to exceed three times ([UNI]\{1,3\}); line 35 satisfied the match. A better expression would have been ___________.