in reply to Simple regular expression problem
I need to split a string
Usually when a person says that, he really wants to use split. I don't see why this would be an exception...
This avoids all the uproar about about non-ascii characters and meets your specification exactly in that it makes no assumptions about the string prior to the digits at the end. It uses a zero-width look-ahead assertion to split without losing characters and it uses the 3 argument version of split to limit our split to two parts (otherwise a string like "abc123" would split into 4 parts.)($name, $num) = split /(?=\d+$)/, $str, 2;
-sauoq "My two cents aren't worth a dime.";
|
---|