Examples of Spanning Characters
Examples of Spanning Characters
- \{N\} Repeat Previous Regular Expression Exactly N Times.
==> 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.
- \{N,\} Repeat Previous Regular N or More Or Times.
==> 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!
- \{N,M\} Repeat Previous Regular Expression At Least N Times.
==> egrep ' X[UNI].$' fortunes
==>
==> egrep ' X[UNI]\{1,3\}.$ ' fortunes
Remember, UNIX spelled backwards is XINU.
Notes:
In the first example demonstrates matching a subexpression exactly a certain amount of times. The expression defined is as follows:
- Match a space
- Then match a non lowercase vowel
- The match a lowercase vowel; which must occur twice
- Then match another non lowercase vowel
- And finally match a space
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:
- Match a space
- Then match a lowercase vowel
- The match a single character that is a non lowercase vowel or an apostrophe; which must occur three or more time (I believe the max value is 255).
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
- Match a space
- Then match an uppercase X
- Then match a any of the three single characters: U, N, or I
- Then match any printable character
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 ___________.