Link to home
Start Free TrialLog in
Avatar of shahrahulb
shahrahulb

asked on

extract

i have string in followin format
app.txt_050405-10:22:25 is up and running now

how do i extract the  "app" from string
Avatar of bob_anastasia
bob_anastasia

well,

If you JUST want to remove it, a quick dirty way is to do this:

$line =~ s/app//gsi;

this will just remove it.
Avatar of shahrahulb

ASKER

app is variable and not constant value
Avatar of FishMonger
When you say 'extract' do you mean you want to remove it or put it into another variable?

#!perl -w

$str = 'app.txt_050405-10:22:25';

$str =~ s/^([^\.]+)//;
$extracted = $1;
print "extracted/removed '$extracted' from $str$/";

C:\Temp>test.pl
extracted/removed 'app' from .txt_050405-10:22:25
ASKER CERTIFIED SOLUTION
Avatar of FishMonger
FishMonger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<quote>
$str =~ s/^([^\.]+)//;
$extracted = $1;
print "extracted/removed '$extracted' from $str$/";
</quote>

if $str contains all '.' (or if it starts with a '.'), this may match a stale $1 from a previous successfull match. As I've heard, this is not a good idea. $n should be accessed only after checking whether the match was successful.

$extracted = $1 if ($str =~ m/^([^.]+)/) ;