At 14:29 -0500 02.02.2001, Kenneth Graves wrote:
>From: Chris Nandor <[EMAIL PROTECTED]>
>>At 12:49 -0500 02.02.2001, Kenneth Graves wrote:
>>>(I.e., why don't character classes work in tr?  \s and \S would be
>>>very convenient.)
>>
>>\d is not a character class, but a metacharacter.  And I guess the answer
>>to "why not" is that metacharacters are for regexes, and tr/// does not use
>>regexes.  It only looks like it does.
>
>\n is a metacharacter, and does work in tr.

Sorry, I meant to say regex metacharacters.  They are different.  \n, \r,
\t, \a, \f, \b and more are string metacharacters, not regex
metacharacters.  All of them can work in a regex ... except for \b, which
has a different meaning in a regex.


>The metacharacters that
>encode single characters work in tr like they do in an interpolated
>strings.  The metacharacters that match multiple characters in a regex
>don't work in tr.  The problem is, my brain keeps insisting that
>       tr/thesechars//d;
>is "really" an optimized version of
>       s/[thesechars]//g; # or [theschar]
>and I keep trying to do
>       tr/\s//d; # doesn't eliminate whitespace

Right.  Because those are regex metacharacters, and tr/// doesn't do regexes.


>I've managed to train a neuron or two to stop making that mistake,
>but it's still annoying.  With utf8, I'd want to eliminate whitespace
>with something like
>       tr/[:space:]//d;
>since I have no hope of memorizing the utf8 equiv of " \t\r\n\f".

I doubt that will work.  You are still talking about regexes.

If you want to do a regex instead of a transliteration, then use s///.

-- 
Chris Nandor                      [EMAIL PROTECTED]    http://pudge.net/
Open Source Development Network    [EMAIL PROTECTED]     http://osdn.com/

Reply via email to