Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: the end of a word

by arturo (Vicar)
on Jul 22, 2002 at 20:22 UTC ( #184220=note: print w/replies, xml ) Need Help??

in reply to the end of a word

A lot depends on what you want to "clean." For the specific case you mention (with all those naughty barewords... put on some quotes, or you'll catch a horrible illness), you might be able to employ the builtin character class \w ("word" characters) or its negation, \W (not "word" characters). The perldoc perlre can help a lot here. Since I can't tell exactly what you're trying to fix, I'll assume you want to get rid of any non-word characters at the end of the string, for which

$directory =~ s/\W+$//;
ought to suffice. The $ anchors the match to the end of the string, and "\W+" matches "one or more non-word characters". It then replaces any such pattern found with nothing.


I mistrust all systematizers and avoid them. The will to a system shows a lack of integrity -- F. Nietzsche

Replies are listed 'Best First'.
Re: Re: the end of a word
by Sara (Acolyte) on Jul 22, 2002 at 20:36 UTC
    thank you all

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://184220]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2023-06-09 08:28 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (35 votes). Check out past polls.