if you're trying to normalize a string so you can make a decent filename out of it- which i get the feeling here (slap me if i'm wrong..)

my $fus=qq|This Is some Funkah Lookin' & Zmellin' "straeyang"|; $fus=~s/\W/_/g; # now $fus equals This_Is_some_Funkah_Lookin____Zmellin_ __straeyang_ #great. super. let's clean that up $fus=~s/_+/_/g; # now $fup equals This_Is_some_Funkah_Lookin_Zmellin_straeyang_ #let's get rid of any _ in ends $fus=~s/^_+|_+$//g; print $fus; # prints This_Is_some_Funkah_Lookin_Zmellin_straeyang #maybe im tight and i don't want any uppercase $fus = lc($fus); #now $fus = this_is_some_funkah_lookin_zmellin_straeyang #anyway.. you get the idea

Maybe you want to get rid of funny chars? like non word chars? then use \W, that means *any* non word characters, as opposed to (\w which are 0-9, a-z, A-Z, _ anyway..)


In reply to Re: stripping characters from a string by leocharre
in thread stripping characters from a string by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.