[Raleigh-talk] Please assist w/regex

Andy Myhr awmyhr at gmail.com
Tue Mar 20 11:16:16 PDT 2007


Wow, that was fast, thank you much (and devin also, whose answer came  
in just as I was implementing yours)...
I'll see what I can do about more "EZ" questions ;)


On Mar 20, 2007, at 14:07, James Olin Oden 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.



More information about the Raleigh-talk mailing list