Have one requirement where suppose we insert value alphanumeric ABC123 then it should output as CCCNNN(Alphabets replace by C and numbers by N)
if value is ABC 123(then CCCSNNN) spcae is replaced by N
if values i ABC then CCC
if values is suppose 1234 then NNNN
How to write a regex for the same please do let me know about the same.

Muhammad Imran AnsariPosted Feb 28, 2022, 9:15 AM
You can try this:
var str = "XY 123";
var str = str.replace(/[A-Z]/g, 'C').replace(/[0-9]/g, 'N').replace(/ /g, 'S');
Output: CCSNNN