JSFiddle - React, Tailwind, and code Playground

by Michael Prosser

JavaScript

var str = '[A-Za-z0-9]{,8}';

// check if it is just a single component first

var hasFirstComponent = false;
var hasSecondComponent = false;
var hasThirdComponent = false;

var firstComponent = '';
var secondComponent = '';
var thirdComponent = '';

if(str.substr(0,1) == '['){

	hasFirstComponent = true;
  
  firstComponent = str.substr(1,str.indexOf(']')-1);

}

if(str.indexOf('{') > -1){

	hasSecondComponent = true;
  
  var sstr = str.substr(str.indexOf('{')+1);
  
  secondComponent = sstr.substr(0,sstr.indexOf('}'));
  
 if(secondComponent.substr(0,1) == ','){
  
  	hasThirdComponent = true;
  	thirdComponent = 'nomorethan';
    
    secondComponent = secondComponent.substr(1);
  
  } else if(secondComponent.substr(secondComponent.length-1,1) == ','){
  
  	hasThirdComponent = true;
  	thirdComponent = 'atleast';
    
    secondComponent = secondComponent.substr(0,secondComponent.length-1);
  
  } else {
  
  	thirdComponent = 'exactly';
  
  }

}

alert(firstComponent);
alert(secondComponent);
alert(thirdComponent);