[EMAIL PROTECTED] wrote:
> Real simple,
>
> I have a string, "$a" for arguments sake, that contains a single
> word. The word will always have exactly 8 characters in it, most
> likely something like "ABCD1234". I need to split this up into two
> strings ($b & $c), the first string needs to contain all the
> characters before the first number in the word ("ABCD" in this
> example), the second string needs everything after, and including,
> the first number in the word "1234" in this example.
>
> Now, substr() would be a walk in the park, except for the fact
> that I can't guarantee the first number will always be in the fifth
> position ... it might come in any position between 3 and 7. How would
> YOU go about doing this? Inquiring minds want to know.
Stay away from the $a and $b ( sort magic variables ).
if there must be at least one alpha, then
if ( /^(\D+)(\d+)/ ) {
$alphapart = $1;
$numericpart = $2;
if ( (length($alphapart) + length(Numericpart) != 8 ) {
# report length differences since the lengths of alpha and
numeric are not 8
}
}
Wags ;) ps If truly only alpha then could replace\D+ with [a-z]+ and add i for
ignore case.
>
> Bill in Brooklyn
>
> _______________________________________________
> Perl-Win32-Users mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs