Re: Perl regular expressions help
- From: Abigail <abigail@xxxxxxxxxx>
- Date: 27 Aug 2005 00:22:03 GMT
Rumpa (sgrumpa@xxxxxxxxx) wrote on MMMMCCCLXXVIII September MCMXCIII in
<URL:news:deo51v$26ui$1@xxxxxxxxxxxxxxxx>:
`' Hi,
`' I am trying to learn perl regular expressions.
`' I have:
`' my $store = q(
`' <store>
`' <book>
`' <title>abc</title>
`' <author>xyz</author>
`' </book>
`' <book>
`' <title>pqr</title>
`' <author>mno</author>
`' </book>
`' </store>);
`'
`' I want to extract the titles only in a loop. How can I do this?
That depends on what is a title. For the given example,
/(abc|pqr)/
will do.
/<title>([^<]+)<\/title>/
works for the given example as well, but it might give false positives.
You are probably much better off with a parser, althouh it is
possible to replace a lot of parsers with regular expressions.
Not that any sane person would want to do it.
Abigail
--
#!/opt/perl/bin/perl -w
$\ = $"; $; = $$; END {$: and print $:} $SIG {TERM} = sub {$ := $_}; kill 15 =>
fork and ($; == getppid and exit or wait) foreach qw /Just another Perl Hacker/
.
- References:
- Perl regular expressions help
- From: Rumpa
- Perl regular expressions help
- Prev by Date: Re: Using Crypt::DSA
- Next by Date: Re: Looking for Regexp that strips newlines inside of a tag
- Previous by thread: Re: Perl regular expressions help
- Next by thread: Re: Perl regular expressions help
- Index(es):
Relevant Pages
|