in reply to Simple regular expression problem

\w will match alphanumeric characters [0-9a-zA-Z_]. So in your regex \w matches digit also. So change it as shown.

Also you are missing a parantheses in second grouping.

$str = "abdbdr23"; ($name,$num) = ($str =~ /^([a-zA-Z]+)(\d{0,})$/) ; print "$name\t$num\n";

Prasad

Replies are listed 'Best First'.
Re^2: Simple regular expression problem
by Tanktalus (Canon) on Oct 03, 2005 at 14:29 UTC

    <shudder> That works fine in English. But not so good in pretty much any other language. e.g., accented characters and the like, or non-roman languages such as Arabic, Hebrew, Hindi, or pretty much any Asian language. Ok, maybe today you don't support them, but maybe tomorrow? Besides that, this regexp is not self-documenting if you mean to say you want to match "letters". Better to use the POSIX classes documented in perlre:

    ($name,$num) = $str =~ /^([[:alpha:]]+)(\d*)$/;
    This does a full unicode match against "alphabet". Which has a very well-defined and globalised meaning.

    I'm also unsure why you use "{0,}" - this has precisely the same meaning as "*". Especially when you used "+" instead of "{1,}". Over everything else, be consistant!