JSFiddle - React, Tailwind, and code Playground

by Amine Tbaik

JavaScript

var test = "[0-9]{2}.[0-9]{3}.[0-9]{3}/[0-9]{4}-[0-9]{2}";


function parse(regexString){
    var regex = /\d{5}/g,
        match,
        model = [];
    while (match = regex.exec(regexString)) {
        if(typeof match[1] == 'undefined'){
            for(var i=0;i<match[3];i++){
                model.push(match[2]);
            }
        }else{
            model.push(match[1]);
        }
    }
    return model;
}

var parsedRegexp = parse(test);
console.log(parsedRegexp)
console.log("Number of characters : " + parsedRegexp.length);
console.log("Character at position 4 must be : " + parsedRegexp[4]);