Graphics Programs Reference
In-Depth Information
that have special meanings to express more complex patterns. These special symbols are
called metacharacters and operators .
For instance, the dot character (.) is a metacharacter that means “any character.” Thus, a
pattern string T.e would match The , Tie , or any other string that has a T followed by
any character followed directly by an e .
Operators in a regular expression typically follow a literal character or metacharacter and
modify how the character is to be matched. For instance, the asterisk ( * ) operator means,
“See the character just before me? If you see that character, that's a match. If you see it re-
peated multiple times, that's a match. If you see nothing (the character occurs zero times),
that's a match, too. But if you see any other character, the match fails.”
Thus, if the pattern string were Bo*o , many strings would match this regular expression:
Boo , Bo , Booo , Booooooo , etc. But Bio and Boot would fail.
A pattern string can contain any number of literal characters, metacharacters, and operat-
ors. Combining them gives you an enormous amount of matching power. You can see the
full list of metacharacters and operators in the documentation for NSRegularExpres-
sion . Here are some examples of regular expressions and strings that would result in a
match:
Pattern Matches
------------------------------------------------
Joh?n
Jon, John
Mike*
Mike, Mik, Mikee, Mikeee, etc.
R|Bob
Rob, Bob
Our original problem (extracting the middle portion of the item's title) may not seem
suited for regular expressions and matching at first, but we can solve it easily using the
same classes.
First, we need to create a regular expression that is a wild card search that returns all item
titles. Take a look at the full titles of the RSSItem s. They all have the same format:
(Subforum) :: (Title) :: (Author)
In trying to construct a pattern string to match this format, we can't use just a literal string
as the pattern. Instead, we can use .* for our search. This combination of the . metachar-
acter and the * operator means “match anything, no matter how long it is.” Thus, our pat-
tern to match the title of every RSSItem will look like this:
.* :: .* :: .*
Search WWH ::




Custom Search