This article mainly introduces the JavaScript in the regular expression of the reverse reference, the need for friends can refer to the
Recently encountered a requirement, pass in a string, insert a space example every three characters: incoming abcd1234 output ABC D12 34 think about it, prepare to write a function The following code is as follows: function Appendspace (s) {V Ar length = s.length; var result = ""; var last = 0; for (var i = 3;i<=length;i=i+3,last = last+3) {result = Result+s.substring (i-3,i) + ""; result = Result+s.substring (last,length); return result; Feel this function is a bit of a dick ... Then replace () the regular expression substitution method code is as follows:/* *$1 represents the first pair of parentheses in a reference matching rule (here is "(. { 3}) "The text that is hit will be output directly without parenthesis */function Insertspace (s) {var result =s.replace (/. { 3})/g, "$"; return result; }