chrisyboy53
9/12/2017 - 9:41 AM

Handy Regex's

Handy Regex's

/*
 * Find functions with certain amount of parameters
 * ^[a-zA-Z0-9]*\.[a-zA-Z0-9]*\(( *[a-zA-Z0-9]* *(\,|\))){4}\;
 */
 
var regex = /^[a-zA-Z0-9]*\.[a-zA-Z0-9]*\(( *[a-zA-Z0-9]* *(\,|\))){2}\;/;

var twoParam = 'obj.meth(param1,param2);';

var threeParam = 'obj.meth(param1,param2, param3);';

function _addText(text) {
  if (document) {
    var body = document.getElementsByTagName('body')[0];
    var tElement = document.createElement('p');
    tElement.innerHTML = text;
    body.appendChild(tElement);
  }
  console.log(text);
}

var results = regex.exec(twoParam);
var resultsText = 'twoParam has found index ' + (results ? 'Yes' : 'No');
_addText(resultsText);

results = regex.exec(threeParam);
resultsText = 'threeParam has found index ' + (results ? 'Yes' : 'No');
_addText(resultsText);