Hi Alexander
Or you can use this
($temp=~ m/([A-Za-z0-9]{5})\.([0-9]{1,2})[+-]([0-9]{1,4})\.([0-9]{1,4})/);
This is more compact and accurate

Thanks and regards
Ajay


-----Original Message-----
From: Alexander Koenig [mailto:alexander.koe...@mpi.nl]
Sent: Tuesday, May 19, 2009 7:25 PM
To: beginners@perl.org
Subject: Re: Simple regex question

You wrote on 05/19/2009 03:18 PM:
> Simple question for the regEXperts out there...
>
> I have a string that is always in the format:  aaaaa.nn+x.y
>
> a is always 5 chars
> n can be 1 or 2 digits
> x can be +/- (with sign), 1-4 digits
> y is always positive (no sign), 1-4 digits

The best I can come up with on the fly would be something like this:

---

#!/usr/bin/perl

use strict;
use warnings;

my @test = ('A123C.11+002.001','FC32G.2-1.0','12B15.01+2145.15');

foreach my $item (@test)
{
print "$item\n\n";
($a,$n,$x,$y)) = $item =~ /(.{5})\.(\d\d?)[-+](\d{1,4})\.(\d{1,4})/;
my ($lengthx, $lengthy) = (length $x, length $y);
print "a = $a, n = $n, x = $x, y = $y, length x = $lengthx, length y =
        $lengthy\n";
}
---

But the real experts can probably compress it much more still.

hth
Alex

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to