```javascript
return text.replace(/%n/g, $count).replace...
```
may do the job here (`%` in regexes don't need to be escaped, do they?)