What kind of pattern you need to write to get, for example, the line 15, 43, 54, 2, 1, 23, 1, 6 ? That is, it is necessary to replace all characters (including spaces) with , - , and so that commas do not repeat.

 var str = '15,43,54, 2, 1л23а1-4 6'; var myPattern = /\D/g; var strА = str.match(myPattern); //паттерн, который должен вернуть 15, 43, 54, 2, 1, 23, 1, 6 console.log(strА); 
  • You have the correct pattern. You need split + join strA=str.split(myPattren).join(",") - nick_n_a
  • You do not understand right now, I get for example: from 15.43.54, 2, s4 6 fffff - 1.5,4,3,5,4,2,4,6 And I want to get 15.43.54, 2,4,6, BUT ALL EQUALLY THANKS - Victor
  • You have already been answered, yes you need + deliver to the template - nick_n_a

1 answer 1

This option. Each sequence of characters other than numbers is replaced by a comma:

 var str = '15,43,54, 2, 1л23а1-4 6'; var myPattern = /\D+/g; var strА = str.replace(myPattern, ','); // патерн который должен вернуть 15, 43 , 54, 2, 1, 23, 1, 6 console.log(strА); 

  • ALL THANK YOU VERY MUCH !!!!!! DIRECT I AM VERY GRATEFUL !!! Right now, I will draw up as a separate function and I will be happy !!!! - Victor