[EMAIL PROTECTED] wrote:
From: John W. Krahn [mailto:[EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
I have string like this. D.PRS.WEB.02.10.001.1 and my requirement is
that I want to remove last dot (.) and all the characters/digit after
that dot with the help of regular expression.
$ perl -le'
$_ = "D.PRS.WEB.02.10.001.1";
print;
s/\.[^.]*\z//;
print;
'
D.PRS.WEB.02.10.001.1
D.PRS.WEB.02.10.001
Thanks John. OOps I did not mentioned one condition while writing the
regular expression.
condition is : If after last dot(.) there are three digit then don't do
anything but if after last dot(.) there are no exactly three digit then
replace that dot(.) and all digits after that dot with space.
$ perl -le'
@x = ( "D.PRS.WEB.02.10.001.1", "D.PRS.WEB.02.10.001.12",
"D.PRS.WEB.02.10.001.123", "D.PRS.WEB.02.10.001.1234",
"D.PRS.WEB.02.10.001.12345" );
for ( @x ) {
print;
s/\.(?![^.]{3}\z)[^.]*\z/ /;
print;
}
'
D.PRS.WEB.02.10.001.1
D.PRS.WEB.02.10.001
D.PRS.WEB.02.10.001.12
D.PRS.WEB.02.10.001
D.PRS.WEB.02.10.001.123
D.PRS.WEB.02.10.001.123
D.PRS.WEB.02.10.001.1234
D.PRS.WEB.02.10.001
D.PRS.WEB.02.10.001.12345
D.PRS.WEB.02.10.001
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/