"Just so you realize that you've hardcoded a solution for a single data set, whereas some of the other posted solutions are more generalized."
Actually, yes. The "hardcoded" solution provided works in a much larger set of scenarios than the home-grown regex solutions provided. What if there are 200 ^M characters before and after the wrapped key? jeffa's solution handles that (these regexes do not). What if every single key wraps, regardless of width? Again, his solution handles that.
The other solutions, while unary and interesting on their own, are actually much more "hardcoded" (i.e. will only work on a very small subset of the strings involved) than the solution jeffa provided.
Can each of the other solutions be modified to work with all scenarios? Yes, sure, but at what cost and maintenance headache a year from now?
Can jeffa's solution be modified to not be so hard-coded? Yes, and with a much longer-term benefit and maintenance advantage over debugging regexes each time the template format changes ever-so-slightly.
|