On Tue, May 19, 2009 at 09:18, Dan Fish <d...@ninemoons.com> wrote:
> 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
snip

What do you mean by chars?  Is any character valid or are only
printable characters valid, or only printable ASCII characters, or
a-z, A-Z, and 0-9?

a is (.{5}) or ([[:print:]]{5}) or ([\x{20}-\x{7e}]{5}) or ([a-zA-Z0-9]{5})
. is [.]
n is ([0-9]{1,2})
x is ([+-][0-9]{1,4})
. is [.]
y is ([0-9]{1,4})


>
>
> Some examples:
>        A123C.11+002.001
>        FC32G.2-1.0
>        12B15.01+2145.15
>
> I need all 4 pieces and the length of x & y. The following works:
>
> my $id= "A123C.11+002.001";
>
> my @tmp = split(/[\.+-]/,$id);
> my $part = $tmp[0];
> my $unit = $tmp[1];
> my $x = $tmp[2];
> my $y = $tmp[3];
> my $xlen = length $tmp[2];
> my $ylen = length $tmp[3];
snip

my ($part, $unit, $x, $y) = / (.{5}) [.] ([0-9]{1,2}) ([+-][0-9]{1,4})
[.] ([0-9]{1,4}) /x
my ($xlen, $ylen) = map length, $x, $y;

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
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