Regex Patterns

2 or more capital letters in a row 2 or more numbers in a row

HTML

<div id="output"></div>

CSS

.space {
    font-weight: bold;
    font-size: 18px;
    margin-left: 10px;
}

JavaScript

/*
goal - 

1) seek two or more capital letters in a row, or two or more numbers in a row
2) insert span tag with spacing class when items are found

*/

//Uncomment one of these variables for either numbers or letters

var pattern = /[A-Z]/; //regular expression for capital letters
//var pattern = /[0-9]/; //regular expression for numbers

//this will be the string we search. it's alphanumeric
var string  = 'A12bc3d45EFghI6jk7lMNOpqrs89tuVWxyZ';

var matches = []; //collection of matched items, used for modification

for(var i = 0; i < string.length; i++) {
    var chars = []; //array to hold matching characters
    
    chars[0] = string.charAt(i);//get next char to compare

    //if this char matches pattern, search neighbors
    if(chars[0].match(pattern)) {
        var j = i+1;
        
        //inner loop to compare neighboring chars
        while(string.charAt(j).match(pattern)) {
         chars.push(string.charAt(j));
         j++; 
         i++;
        } 
        if(chars.length > 1) {
          matches = matches.concat(chars);
        }        
    }
}

 matches.forEach(function(char){
     string = string.replace(char,'<span class="space">'+char+'</span>');
 });

//write out the string with spaces between the matched letters or numbers
$("#output").html(string);