title: golang regexp replace single digits
body: <p>I'm trying to replace single digits, only if they are not accompanied by a word character. For e.g.</p>
  
  <p><code>[*:*:1] a2b*d 3n 4q test 5 test 6</code></p>
  
  <p>Should be change into</p>
  
  <p><code>[*:*:*] a2b*d 3n 4q test * test *</code></p>
  
  <p>In the above list, the numbers 1, 5 and 6 have been replaced with *, but 2, 3 and 4 are not replaced as they are accompanied by a word character.</p>
  
  <p>The below code works, but partially </p>
  
  <p><a href="https://play.golang.org/p/OC6bk4PLyq" rel="nofollow noreferrer">https://play.golang.org/p/OC6bk4PLyq</a></p>
  
  <pre><code>s := "[*:*:1] a2b*d 3n 4q test 5 test 6"
  re := regexp.MustCompile("[^0-9A-Za-z_][0-9]+[^0-9A-Za-z_]")
  s = re.ReplaceAllString(s, "*")
  fmt.Println(s) // Prints - [*:** a2b*d 3n 4q test*test 6
  </code></pre>
  
  <p>Here, I would like the <code>:</code> and the <code>]</code> in the first word to be retained and the spaces around <code>5</code> to be retained. Also the <code>6</code> is not replaced.</p>
  
  <p>Any suggestions on how this can be achieved in Go.</p>