----- Original Message -----
From: Gross, Stephan <[EMAIL PROTECTED]>
To: 'Beginner Perl' <[EMAIL PROTECTED]>
Sent: Friday, May 11, 2001 5:26 PM
Subject: Regexp Question Again
> I wasn't clear last time. I wrote:
> >I want to match the following:
> >1) the letters "PT"
> >2) a space or nothing
> >3) a word that may or may not be in parentheses or even not exist
> >and return item #3 (which may be null)
> >Example:
> >PT (XYZ) or PT XYZ or PTXYZ or PT
> >should return "XYZ" except the last case, which should return "".
>
> >I can do everything except the parentheses case. Any ideas?
>
> The problem is the final parenthesis. If I use (.*) or (\w*) then it
> swallows the final parenthesis. I want to discard it if it is present.
> Also, the XYZ term may include spaces.
>
> None of the solutions you guys sent do this. Willing to try again?
>
> Thanks again.
i tried
/PT\s*\(?(.*?)\)?/i
But making .* non greedy kinda spoils it. It will work with a non greedy .*
but that will eat the closing right bracket.
Following works, but doesnt deserver any price for beauty....
for ("PT (XYZ)", "PT XYZ", "PTXYZ", "PT"){
$me = $_ ;
$me=~s/PT|\s|\(|\)//g;
print "have:$me\n";
}
> _______________________________________________________
> Stephan Gross Loral Skynet 908-470-2388
> <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]
>
>
>