Yngvarr

Generation

generate functionFri, 14 Apr 2023

pregmatch array in string

function preg_match(str, data){ // check if it is string if(typeof(str) !== 'string'){ console.error('type error, not a string'); return; } // check if it is array if(!Array.isArray(data)){ console.error('type error, not array'); return; } // check if it's a string in array data.forEach(function(item, index){ if(typeof(item) !== 'string'){ console.error('type error, not a string'); return; } }); // check if str match array var flag = 0; data.forEach(function(item, index){ if(str.indexOf(item) !== -1) flag++; }); if(flag == 0) { console.error('no match'); return; }else{ return flag; } } preg_match

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant