remove up to _ in perl using regex?

perl, regex

Solution

This is a bit more verbose than it needs to be, but would be probably more valuable for you to see what's going on:

my $astring = "124312412_hithere";
my $find = "^[^_]*_";
my $replace = "_";

$astring  =~ s/$find/$replace/;

print $astring;

Also, there's a bit of conflicting requirements in your question. If you just want `hithere` (without the leading `_`), then change it to:

$astring  =~ s/$find//;

Problem

How would I go about removing all characters before a "_" in perl? So if I had a string that was "124312412_hithere" it would replace the string as just "hithere". I imagine there is a very simple way to do this using regex, but I am still new dealing with that so I need help here.

Original source