1
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScript 複数の文字列をAND検索で探し出したい

Posted at
search.js

/*
 *  複数の文字列をAND検索で探し出したい
 *  大文字小文字も区別しない
 */
var line  = ["1tEst","test2","3test"];
var search_string = "teSt 2";
var match_flag = isMatchMulti(line,search_string);

function isMatchMulti(line,search_string) {
  var separatorString = /\s+/;
  var arrayStrig = search_string.split(separatorString);  
  var match = new Array();
  for(var i = 0 ; i < arrayStrig.length; i++ ){
    reg = new RegExp("(?=.*" + arrayStrig[i] + ")","i");
    match[i] = false;      
    for(var j = 0 ; j < line.length; j++ ){
        if(line[j].match(reg)){
          match[i] = true;
        }
    }   
  }
  var match_flag = false;
  if(0 < match.length){
    match_flag = true;
  }else{
    match_flag = false;
  }
  for(var ii = 0 ; ii < match.length; ii++ ){
    if(match[ii] == false){
      match_flag = false;
    }
  }
  return match_flag;
}

1
7
8

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?