in reply to Re: the end of a word
in thread the end of a word

[^a-z-A-Z] can be more succintly put as \W . (That's a capital W in case your font doesn't make it clear.)

--
જલધર

Replies are listed 'Best First'.
Re: Laziness is one of the three virtues!
by Ovid (Cardinal) on Jul 22, 2002 at 20:41 UTC

    That's a common misconception regarding \w and \W. The "word" characters (depending upon locale) are typically letters, underscores, and digits. Thus, the \W will not remove underscores or digits from the end.

    $ perl -e '$_="foobar_";s/[^a-zA-Z]+$//;print' foobar $ perl -e '$_="foobar_";s/\W+$//;print' foobar_ $ perl -e '$_="foobar9";s/\W+$//;print' foobar9

    Update: I pointed out a bug in your code only to realize a bug in mine :) My first example doesn't respect locale settings. I should be using POSIX character classes.

    $ perl -e '$_="foobar_";s/[[:^alpha:]]+$//;print' foobar

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.