//the callback definition
function replacer(match, p1, p2, p3, offset, string){
// match is the matched substring
// p1 is non-digits, p2 digits, and p3 non-alphanumerics
// offset is the offset of the matched substring within the total string being examined
// string is the total string being examined
return [p1, p2, p3].join(' - ');
}
// using replace method with replacer callback
newString = "abc12345#$*%".replace(/([^\d]*)(\d*)([^\w]*)/, replacer); |