var str = "sos"; str = str.replace(/([az])(\.)([az])/g, "$1$3"); // => "so.s" 

How to get "sos"?

  • Because the first match captures the letter о and for the second time only .s. remains .s. regex101.com/r/cQ0wH4/1 - Visman
  • Как получить "sos"? - replace points with an empty string? - KoVadim
  • @Visman How to get "sos"? - user208916
  • KoVadim has already given you the answer. - Visman
  • @Visman He asked and did not answer. - user208916

1 answer 1

 var str = ".ss....os"; str = str.replace(/([az])\.+(?=[az])/gi, "$1"); alert(str); 

To the points, the letter is captured ([az]) , after the point there is no (?=[az]) and replaced with the captured letter $1 .

  • Cool, but I forgot about (? =) - user208916