For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > regex remove of strings etc









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author regex remove of strings etc
Brent Clark

2005-08-23, 7:55 am

Hi all

I need to remove the string "room" (notice the check for a space too) and also to check for spaces in the beginnig and then maybe at the end
of the total string.

$p110rm01 =~ s/(\sroom|^\s*|\s*$)//igo;

Would someone be so kind as to check this for me.

Kind Regards
Brent Clark
John W. Krahn

2005-08-23, 7:55 am

Brent Clark wrote:
> Hi all


Hello,

> I need to remove the string "room" (notice the check for a space too)
> and also to check for spaces in the beginnig and then maybe at the end
> of the total string.
>
> $p110rm01 =~ s/(\sroom|^\s*|\s*$)//igo;
>
> Would someone be so kind as to check this for me.


You don't need the /o option as the regular expression is already compiled.

perldoc -q "/o"

And you apparently don't need the capturing parentheses.


You probably want something like this:

for ( $p110rm01 ) {
s/\sroom//ig;
s/^\s+//;
s/\s+$//;
}



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com