To strip off a prefix in a variable..

C

clearguy02

Hi all,

I have the following variable:

$a = "xxx_active_jsmith";

Now I want to strip ohf the prefix, xxx_active_ and want to store only
the id, jsmith into the variable $b. That means, it should be $b =
"jsmith";

How can I do that?

Thanks
J
 
M

Martijn Lievaart

Hi all,

I have the following variable:

$a = "xxx_active_jsmith";

Now I want to strip ohf the prefix, xxx_active_ and want to store only
the id, jsmith into the variable $b. That means, it should be $b =
"jsmith";

How can I do that?

$a =~ s/^<a-regexp-for-the-prefic>//;

HTH,
M4
 
G

Gunnar Hjalmarsson

I have the following variable:

$a = "xxx_active_jsmith";

Now I want to strip ohf the prefix, xxx_active_ and want to store only
the id, jsmith into the variable $b. That means, it should be $b =
"jsmith";

How can I do that?

($b) = $a =~ /([a-z]+)$/;
 
J

John W. Krahn

I have the following variable:

$a = "xxx_active_jsmith";

Now I want to strip ohf the prefix, xxx_active_ and want to store only
the id, jsmith into the variable $b. That means, it should be $b =
"jsmith";

How can I do that?

( $b ) = $a =~ /([^_]+)\z/;


( $b = $a ) =~ s/.*_//;



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,209
Messages
2,571,086
Members
47,684
Latest member
Rashi Yadav

Latest Threads

Top