Re: String Parsing
- From: Josef Moellers <josef.moellers@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 18 Aug 2005 08:40:59 +0200
Dan wrote:
I am just starting to learn some parsing techniques in Perl.. Can anyone give me an example of how I might parse a string, replacing certain instances of words with other words? For example, replacing "Ave." with "Avenue", etc.
It's not "parsing" in the broad sense, but rather "matching a regular expresison" in Perl lingo (though I wouln't be surprised if anyone came up with a regular expression matching a valid sentence in modern English B-{).
$string = 'Madison Ave.'; $string =~ s/Ave\./Avenue/; print "$string\n";
Note that regular expressions in Perl are extremely powerful (more powerful than a megaton of TNT) and the "s" operator has numerous options to control how matching (e.g. "greedy" vs "non greedy") and replacing (e.g. "once" vs. "always") is done.
You should definitely read perldoc perlop and perldoc perlre
-- Josef Möllers (Pinguinpfleger bei FSC) If failure had no penalty success would not be a prize -- T. Pratchett
.
- Follow-Ups:
- Re: String Parsing
- From: Dan
- Re: String Parsing
- References:
- String Parsing
- From: Dan
- String Parsing
- Prev by Date: Re: Interfaces and Type Safety, Dynamic Typing (OOP Newbie in Perl)
- Next by Date: Trying to read xml output from Acrobat form
- Previous by thread: String Parsing
- Next by thread: Re: String Parsing
- Index(es):
Relevant Pages
|