|
Posted by Janwillem Borleffs on 02/23/06 00:16
Hemanth wrote:
> Hello,
>
> How do I find the first and last non-numeric char positions (using
> regexp) in an alphanumeric string?
>
> For example,
> 99ABC1A => should return 2, 6
> DE8A1 => should return 0, 3
>
$value = 'DE8A1';
if (preg_match("/([a-z]).*([a-z])/i", $value, $m, PREG_OFFSET_CAPTURE)) {
$first = $m[0][1];
$last = $m[count($m)-1][1];
print "First: $first, last: $last";
}
Navigation:
[Reply to this message]
|