A function to split an string of alphabets and numbers into arrays and sort them respectively
You can use RegEx to extract the sequence of alphabets or numbers.
To match alphabets/number, use character class in Regular expression as below

/[A-Z]+|[0-9]+/


to match all occurrences, use g(global) flag.

After extracting sequences, use Array#reduce with Array#sort &amp; Array#join to get the sorted string.



const str1 = 'AYUKB17053UI903TBC';
const str2 = 'ABKUY01357IU039BCT';

console.log(str1
  .match(/[A-Z]+|[0-9]+/g)
  .reduce((a, c) =&gt; a + [...c].sort().join(''), '')
    === str2
);