[Raleigh-talk] Please assist w/regex
devin at nacredata.com
devin at nacredata.com
Tue Mar 20 06:10:43 PDT 2007
$name =~ s/ \([^\)]+\)//g;
-- devin
--- "James Olin Oden" <james.oden at gmail.com> wrote:
> On 3/20/07, Andy Myhr <awmyhr at gmail.com> wrote:
> > Hello all, I am having an issue with regular expressions in Perl. I
> > have the following:
> >
> > $name = "Sun (TM) Enterprise 250 (2 X UltraSPARC-II 296MHz)";
> >
> > What I want is:
> >
> > $name = "Sun Enterprise 250";
> >
> > But if I use this:
> >
> > $hwname =~ s/ \(\w+\)//g;
> >
> Try:
>
> $name =~ s/ \([^)]+?\)//g;
>
> Two points...the string "(2 X UltraSPARC-II 296MHz)" has numbers and
> spaces both of which are not word characters, and you definately need
> to put the question mark after the plus so your regular expression is
> no longer greedy, otherwise you'd match:
>
> (TM) Enterprise 250 (2 X UltraSPARC-II 296MHz)
>
> Cheers...james
>
> P.S. Keep these easy questions comming it will distract me from perl
> memory leaks and other things that are all around painful.
> _______________________________________________
> Raleigh-talk mailing list
> Raleigh-talk at pm.org
> http://mail.pm.org/mailman/listinfo/raleigh-talk
>
More information about the Raleigh-talk
mailing list