On Mon, 7 May 2001, Johan Groth wrote:

> Hi,
> I want to strip a variable of all characters including a token, i.e.
> aaa_bbb_ccc_ddd would become bbb_ccc_ddd.  As you can see I want to get rid of
> aaa_. Does anyone know how to acomplish this in Perl?
> 
> I've tried:
> $tmp = "aaa_bbb_ccc_ddd"
> $tmp =~ /^\w+_/
> $tmp = $';
> 
> but that results in $tmp eq "ddd" instead of "bbb_ccc_ddd".

When you say "all characters" I'd assume you mean "all letters and
numbers", given your example.

If you have a look at perlre:

       In addition, Perl defines the following:

           \w  Match a "word" character (alphanumeric plus "_")

you'll see that \w includes the '_' character.

You have a couple of choices here on how to specify your match then,
either by modifying \w:

   $tmp =~ s/^[^\W_]+_//;

or by literally choosing the characters you want to match (preferably
using ranges):

   $tmp =~ s/^[a-z0-9]+_//i;

The main problem with the first is that unless you've seen character
classes used that way, you're likely to get mixed up on how it works.

-- 
Tony Cook

Reply via email to