SPUG: multi-line substition, all at once.
Ryan Corder
ryanc at greengrey.org
Wed Jun 24 15:49:24 PDT 2009
Greetings all,
I'm trying to do a multi-line substitution of a particular sort and things
aren't quite working out. I've been grinding at it for a little bit now
to the point that I think it's time to ask for some assitance. I'm using 5.10.
Say I have the following:
my $code=<<__CODE__;
: sub hello {
: say "Hello World!";
: }
__CODE__
I would like to get back:
[code] sub hello {
say "Hello World!";
}
[/code]
I've been playing around with the zero-width lookbehind assertions, but it
seems as if the positive (?<=) and negative (?<!) behave differently. Both
are supposed to make the match, but not include it in $&. Negative works
that way, but positive is including or so it seems. Here is what I have so
far...
$code =~ s@(?:(?<=\s\:).*)+@"[code]$&[/code]"@esg; (gives me)
:[code] sub hello {
: say "Hello World!";
: }
[/code]
$code =~ s@(^(\s\:)(.*)$)+@"[code]$3[/code]"@esg; (gives me)
[code] sub hello {
: say "Hello World!";
: }
[/code]
Both are close in their own ways, but no cigar. I've tried other permutations
of the regex to no avail.
I know I could do this with two regex, but for reasons that are not pertinent
to the discusion, I would really like to do this with one.
Any hints?
thanks.
ryanc
--
Ryan Corder || () ASCII ribbon campaign
<ryanc at greengrey.org> || /\ against HTML email
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x1CB59D69
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20090624/c9df6b4f/attachment.bin>
More information about the spug-list
mailing list