JS string to remove consecutive repeating characters
() and \number are used to denote duplicates in the regular number of parentheses, such as: (\d) \1 means repeating the first matching block (\d) is equivalent to if (\d) match to A, the expression is AA
The corresponding can: (some) \1* or (some) \1+ or (some) \1? Represents repeating the first match to get the content any time or at least once or 0 times
1 vars = "1122333455";2 3 varS1 =s;4 varC;5 varCC = S.match (/(\d) \1+/g);//11,22,333,55 of course here () \1* is also possible (because the following is a replacement): 11,22,333,4,556 for(vari = 0;i<cc.length;i++){7 8c = cc[i].substring (0,1);9S1 =S1.replace (cc[i],c);Ten One } A -alert (S1); 12345
JS string to remove all repeating characters and sort the final string
1 vars = "1234321ABACCC";2 varS1 = S.split (""). Sort (). Join ("");3 varCC = S1.match (/(.) \1+/G);//11,22,33,AA,CCC of course here () \1* is also possible (because the following is a replacement): 11,22,33,4,AA,B,CCC4 for(vari = 0;i<cc.length;i++){5 6c = cc[i].substring (0,1);7S1 =S1.replace (cc[i],c);8 9 }Ten Onealert (S1);//1234ABC
JS string to remove consecutive or all repeating characters