On Thu, 2004-05-20 at 01:21, meb wrote: > Maybe this is because I'm a newbie, or maybe it's because I'm trying to > modify RSS text. This is a perl script for a web site. > > In any case, there's a feed that includes the author at the end of the > (looong) description. I'd like to limit the decsription to the first 20 > words, add an ellipsis (...) and add the author's name, like so: > > These are the first 20 words of this item, and it's really... By Joe Schmo. > > > My regex looks something like this: > > (Save 1st 20 words): > > /^(\w|\W){20}/g > > (Save author tag - always starts with By and ends with period. I think this > will also ignore periods in middle initials): > > /By\s?+\.$/g > > > My problem is that I can't figure out how to modify the string. I've even > tried $intro + "..." + $author, but that didn't work. I also tried a lot of > different constructions, like ($intro = $fullDesc) =~ /^(\w|\W){20}/g
$intro =~ s/(?<=^(\w|\W){20}).*(?=By.*$)/... /; untested :-) For replacing something, use $var =~ s/regular_expression/what_you_want_as_a_replacement/ What I've done was to replace anything having 20 words before and a "By.*" after with "... " To concatenate strings, use a dot (.), like this: $var = $intro . "... " . $author HTH, jac > If anyone could provide any insight (or a Regex for Dummies page), I'd > appreciate it. > > Thanks. -- Josà Alves de Castro <[EMAIL PROTECTED]> Telbit - Tecnologias de InformaÃÃo -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>