in reply to Simple regex
Try something more like this:
#!/usr/bin/perl use strict; #use LWP::Simple; #my $content = get("http://www.url.com/scripttemplate.shtml"); my $breakline = "<!-- SCRIPT TEMPLATE BREAKS HERE -->"; my $content = "This is the first part\n" . $breakline . "This is the l +ast part\n"; $content =~ m|(.*)$breakline(.*)|s; print "First Var contains: $1"; print "Second Var contains: $2";
This produces
First Var contains: This is the first part Second Var contains: This is the last part
You don't need the while loop, since you're not checking line by line. You want to search the entire string in one pass. That's what the /s modifier is doing in the regex...it's ignoring the line endings.
HTH,
Larry
UPDATE: ysth's explanation is much better than the one I provided here. Not only that, it's correct, too. :) The /s modifier is not ignoring the newlines. It's allowing the . to match newline characters as well. My haste caused me to misrepresent what was actually happening. :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple regex
by ysth (Canon) on Jan 18, 2005 at 04:22 UTC |