in reply to Splitting string (regex) while keeping the separator?
If you want to have it attached to the previous item, you need to make it a zero-width look-behind:
split(/(?<=[KR])(?!P)/, $a);
Also you have a few errors in your script that prevent the snippet you posted from producing the output you show. (Mis-named variables, missing semicolon).
|
|---|