Just curious, what if instead of replacing ONE boy, we are going to replace N boys? substr will definitely fail if the replacement string is of a different length?
You replied to my post, but I think you intended to ask someone else this question — someone who used substr in his or her solution.
My solution works with any arbitrary regular expression pattern and any arbitrary replacement string. I think my solution is the one most likely to earn the OP an A+.