in reply to Regular Expn Problem

I'm not sure I can explain why this is, but the "?" at the end of the regex is unnecessary -- in fact, it is redundant, because it's doing the same thing as the "(?:...)" operator. Get rid of the final "?" and I believe it will work. (It seemed to make a difference on a small test string that I tried.)

update: Here's a simple demonstration -- compare the outputs of these two commands:

perl -e '$_ = "one two three four"; print $1,$2,$/ if (/(one) .+?(?: t +hree (four))/)' perl -e '$_ = "one two three four"; print $1,$2,$/ if (/(one) .+?(?: t +hree (four))?/)'
For me, the first one prints "onefour", and the second just prints "one". (Anyway, I think I prefer Roy Johnson's approach.)

Replies are listed 'Best First'.
Re: Re: Regular Expn Problem
by venkatr_n (Sexton) on May 10, 2004 at 06:00 UTC
    (?:) simply means the parenthesis is non-capturing. It is not a conditional.