klattimer has asked for the wisdom of the Perl Monks concerning the following question:

Hi i've been using regular expressions for quite some time now and i have a problem with a very simple one.

The regular expression is supposed to take in a multiline string and strip out any tabs found in the string using this regular expression

$actionData =~ tr/\t//sm;
as i understand it tr transposes the first chunk to the second chunk in this case \t (tab) to nothing.

and sm will process the string as a multiline string.

Thanks in advance

Karl

edited by ybiC: retitle from "Problematic regular expression"

Replies are listed 'Best First'.
(jeffa) Re: Strip tabs from multi-line string
by jeffa (Bishop) on Jul 28, 2003 at 14:57 UTC
    pick one:
    $actionData =~ tr/\t//d;
    or
    $actionData =~ s/\t//g;
    Since you aren't dealing with . or anchors, the m and s modifiers for s/// are not necessary.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Strip tabs from multi-line string
by diotalevi (Canon) on Jul 28, 2003 at 14:58 UTC

    That isn't a regular expression. It sort of looks like one but its not. In fact, that's a transliteration and it doesn't use the /sm flags. You wanted either tr/\t//d or s/\t+//g.

Re: Strip tabs from multi-line string
by Lachesis (Friar) on Jul 28, 2003 at 15:04 UTC
    I think you might be confusing transliteration with substitution
    When you use the tr operator you only have 3 options ( copied from perldoc perlop)
    c Complement the SEARCHLIST.
    d Delete found but unreplaced characters.
    s Squash duplicate replaced characters.

    If you want to strip out tabs using tr you would do something like $actionData =~ tr/\t//d; The substitution equivalent would be  $actionData =~ s/\t//g
OT Sidebar, was Re: Strip tabs from multi-line string
by RMGir (Prior) on Jul 28, 2003 at 16:11 UTC
    My first reaction when I saw tr///sm was a Princess Bride flashback: "...that word. I do not think it means what you think it means." =)
    --
    Mike
Re: Strip tabs from multi-line string
by klattimer (Initiate) on Jul 28, 2003 at 15:01 UTC
    Thank you both ;))