Tags

,

Javascript sprintf

function sprintf(format, etc) {
  var arg = arguments;
  var i = 1;
  return format.replace(/%((%)|s)/g, function (m) { return m[2] || arg[i++] });
}

Regex, check if the string1 matches to another string2

function checkRegex() {
  var str = 'helloo';
  var pattern = /^(?!.*(hello))/ig;
  var n = pattern.test(str);
  console.log('n1:', n); <-- it will return FALSE bec the pattern DONT MATCHES the str

  var str = 'helloo';
  var pattern = /^(?!.(hello))/ig;
  var n = pattern.test(str);
  console.log('n2:', n); <-- it will return TRUE bec pattern MATCHES the str

  var str = 'hello';
  var pattern = /^(?!.(hello))/ig;
  var n = pattern.test(str);
  console.log('n3:', n); <-- it will return TRUE bec pattern MATCHES the str
}
Advertisements