Rexexp on part of a string

Mike Whitaker mike at altrion.org
Tue Feb 19 11:48:34 GMT 2008


On 19 Feb 2008, at 11:21, virtualsue wrote:
>
>> s/andrew(?=.*\#)/black/g;
>
> If I split on # then what happens if $x contains 'print  
> "==#andrew#andrew#===\n"  # more andrew'?
>
> Maybe the data would never look like that, but calling them  
> comments and using the '#' to delineate them makes you wonder.

GPWM.

s/andrew(?=.*#[^#]*$)/black/g; # fixed to only ignore trailing comment

# And yes, this breaks if your comment has a # in it

PPI? :)
--
Mike Whitaker - mike at altrion.org


--
Mike Whitaker    | Yahoo! UK Ltd - internal CMS team
mike at altrion.org | Perl developer, writer, guitarist, photographer
Y!: tuxservers   | Blog: http://perlent.blogspot.com/
IRC: Penfold     |




More information about the london.pm mailing list