Jess Balint wrote: > > From: John W. Krahn [mailto:[EMAIL PROTECTED]] > > > > M Z wrote: > > > > > > I was wondering if someone could point me in the right > > > direction for the following regex. > > > > > > s/(.{1,100}(?: |(\-))/$1$2\n/g; > > > > > > Please help on the second (?: |\-) > > > I am trying to match either a single space ' ' > > > or a - after 100 other characters and I want to save > > > the - but not the ' ' > > > thereby $2 being undefined if ' ' is found after 100. > > > > > > I'm ok with it being undefined but I'm not sure if the > > > above regex is valid, in fact I don't think it works > > > the way I want but needed to write it like that to > > > express what I wanted done > > > > s/(.{1,100})( |-)/$1 . ($2 eq '-' && $2) . "\n"/eg; > > What exactly does this ($2 eq '-' && $2) do?
It is equivalent to: if ( $2 eq '-' ) { $2 } else { '' } > Must it be in parenthesis? Yes it must. $ perl -MO=Deparse -e 's/(.{1,100})( |-)/$1 . ($2 eq "-" && $2) . "\n"/eg;' s/(.{1,100})( |-)/$1 . ($2 eq '-' && $2) . "\n";/eg; $ perl -MO=Deparse -e 's/(.{1,100})( |-)/$1 . $2 eq "-" && $2 . "\n"/eg;' s/(.{1,100})( |-)/$2 . "\n" if $1 . $2 eq '-';/eg; Without the parenthesis it would be interpreted as: if ( $1 . $2 eq '-' ) { $2 . "\n" } else { '' } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]