LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Sunday, February 7, 2021

正規表現でAND検索を試してみる3


のパターンを動的に作る方法を分解したコード。

"文字列1", "文字列2"を配列で渡して

こういう結果を得たくて書いたコードです。
 ^(?=.*文字列1)(?=.*文字列2)



コード.gs
function myFunction() {
  var values = ["文字列1", "文字列2"];
  var pattern = createAndSearchPattern(values);
  Logger.log(pattern);
}

function createAndSearchPattern(values) {
  var pattern = "^";
  for(var i = 0; i < values.length; i++) {
    pattern += "(?=.*" + values[i] + ")";
  }
  return pattern;
}



Latest post

Creating a template copier app in Google Apps Script

Introduction This article will show you a template copier application in Google Apps Script.  This application will automatically copy a t...