Monday, 28 October 2019

perl strip spaces from both side of string?

Method1:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~s/^\s+|\s+$//g;


print $unmai;


Method2:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~s/^\s+(.*)\s+$/$1/g;

print $unmai;


Method3:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~s/^(\s+)([\w|.|\s]+)(\s+)$/$2/eg;

print $unmai;



Method4:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~s/^(\s+)([A-Za-z\s]+)(\s+)$/$2/eg;

print $unmai;


Method5:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~s/^(\s+)(\b[A-Za-z\s]+\b)(\s+)$/$2/eg;

print $unmai;


Method6:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~s/^(\s+)([\s|.|\S]+)(\s+)$/$2/eg;

print $unmai;


Method 7:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~s/^(\s+)(.*)(\s+)$/$2/eg;

print $unmai;


Method 8:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~s/^(\s+)([^.]*)(\s+)$/$2/eg;


print $unmai



Method 9:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~s/^(\s+)([\w\d\S.\s_-]*)(\s+)$/$2/eg;

print $unmai



Method 10:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~s/^\s+|((?:$|(?:\.\s))*)(\s+)$//g;


print $unmai;



Method 11:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~/(?m)\W*(.*?)\W*$/g;

print $1;


Method 12:

$unmai=" jaathi enbathu oru tholil thavira athu oru mayirum illai yaar vandumaanalum entha tholilum seyyalam ";

$unmai=~/\s*((\w+)[^;]+\s(\w+);?).*/g;

print $1;



kaavannan perl blogspot

Labels: , , ,

0 Comments:

Post a Comment

Note: only a member of this blog may post a comment.

<< Home