By adding the \W as in
$temp =~ s/^[a-z0-9\W]+_//i;
You can also strip any punctuation such as ' and " from the string.


----- Original Message -----
From: Brett W McCoy <[EMAIL PROTECTED]>
To: Johan Groth <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, May 07, 2001 9:32 AM
Subject: Re: regexp trouble


> On Mon, 7 May 2001, Johan Groth wrote:
>
> > 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 = $';
>
> This did it for me.
>
> $tmp =~ s/^([A-Za-z]+_)(.*)/\2/;
>
> I think the problem is that \w matches an underscore also, and the regexp
> is being greedy as well.  There's probably an even better way to do it
> (especially if your strings have foreign characters at it), but that was
> what occurred to me off the top of my head.
>
> -- Brett
>    http://www.chapelperilous.net/btfwk/
> ------------------------------------------------------------------------
> The price one pays for pursuing any profession, or calling, is an intimate
> knowledge of its ugly side.
> -- James Baldwin
>

Reply via email to