regex - Perl: Remove non-letter, non-number characters from string -
new perl, have problem i'm hoping can me out with.
i have perl string allowed contain letters z (capital , lowercase), numbers 0 9, , "-" , "_" characters. want remove non-matching characters string, leaving rest untouched. "hell@_world" become "hell_world". know there's simple, easy way of doing i'm new perl , don't know how approach this. appreciated.
you use substitution ^
(not) regular expression. while perl offers shortcuts, can see parts more this:
$string =~ s/[^[:alnum:]_-]//g;
where [:alnum:]
character class alphabetic , numeric characters. "-
" last in brackets avoid confusing part of range of characters.
Comments
Post a Comment