 <p>You can try the regex <code>\b$</code> which ensures there's a match where a 'word' ends, and replace with <code> - digit</code> (or <code>\b(\n|$)</code> with a replacement of <code> - digit$1</code> if you don't want to use multiline)</p> <p><a href="https://regex101.com/r/kZ1gX6/1" rel="nofollow">regex101 demo</a></p>