Multiline String, Filter by Text
Multiline String, Filter by Text
Filters a multiple-line string with any search text. Only lines that contain the search text are output. If you want an OR search with multiple texts, specify them as a comma-separated list such as “USA, U.S., United States”.
Configs
  • A: Select STRING DATA for Multiline String *
  • B: Set Search Texts (eg “USA” “USA,U.S.” ) *#{EL}
  • C: Select STRING DATA for Filterd String (update) *
Script (click to open)
// GraalJS Script (engine type: 2)
// (c) 2021, Questetra, Inc. (the MIT License)
// Notes:
// Cannot specify search terms that contain a comma.
// For "AND search", try to place this Automated Step serially.
// Special characters in search text settings have no meaning (literal string).
// Notes(ja):
// カンマを含む検索語は指定できません
// "AND検索" は自動工程の直列配置をお試しください
// 検索テキスト設定の特殊文字に意味はありません(リテラル文字列)


//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA     = configs.get( "conf_DataIdA" ) + "";     // config required
const searchTexts = configs.get( "conf_SearchTexts" ) + ""; // config required
const dataIdC     = configs.get( "conf_DataIdC" ) + "";     // config required

if( searchTexts === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Search Texts} is empty \n" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
const inputString = engine.findDataByNumber( dataIdA ) + "";
const arrInputString = inputString.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " String {A}, number of lines: " + arrInputString.length );


//// == Calculating / 演算 ==
let   outputString = "";
const arrSearchTexts = searchTexts.split(",");
for( let i = 0; i < arrSearchTexts.length; i++ ){
  engine.log( " AutomatedTask Search Text[" + i +"]: " + arrSearchTexts[i] );
  if( arrSearchTexts[i] === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {Search Text[" + i +"]} is empty \n" );
  }

}
for( let i = 0; i < arrInputString.length; i++ ){
  for( let j = 0; j < arrSearchTexts.length; j++ ){
    let contain = new RegExp( arrSearchTexts[j]
                              .replace(/[.*+?^=!:${}()|[\]\/\\]/g, '\\$&')
                            ); // Escaping for a literal string search
    // For a wider range of values, comment out and use Patterns with special characters
    if( contain.test( arrInputString[i] ) ){
      outputString += arrInputString[i];
      outputString += "\n";
      break;
    }
  }
}
outputString = outputString.replace(/[\n]*$/, "");


//// == Data Updating / ワークフローデータへの代入 ==
if( outputString === "" ){
  engine.log( " AutomatedTask DataUpdating: Output Text empty" );
}
engine.setDataByNumber( dataIdC, outputString );

} //////// END "main()" /////////////////////////////////////////////////////////////////

Download

2021-07-09 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/multiline-string-filter-by-text-2021/
The Add-on import feature is available with Professional edition.

Notes

  1. Cannot specify search terms that contain a comma.
  2. For “AND search” try to place this Automated Step in series.
  3. Special characters in search text settings have no meaning (literal string).

Capture

Filters multiple-line string with any search text. Only lines that contain the search text are output. If you want an OR search with multiple texts, specify them as a comma-separated list such as "USA, U.S., United States".

See also

2 thoughts on “Multiline String, Filter by Text”

  1. Pingback: Multiline String, Filter by Text – Questetra Support

  2. Pingback: TSV String, Filter by Text – Questetra Support

Comments are closed.

%d bloggers like this: