String, Replace All
String, Replace All

Replaces all the search strings by the replacement string. All matches are case sensitive. For example, it is possible to completely replace the string “XXXX-XX-XX” in the template text with “2020-05-11”.

(C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/string-replace-all/

Configs
  • A: Set String * #{EL}
  • B: Set Search String * #{EL}
  • C: Set Replacement String * #{EL}
  • D: Select STRING DATA for Replaced String (update) *
Script (click to open)

// GraalJS Script (engine type: 2)
// 
// Notes:
// Regular expressions cannot be used in the search string.
// Can also replace strings that include line breaks and tabs.
//
// Notes (ja):
// 検索文字列の設定に正規表現は利用できません。
// 改行コードやタブコードを含む文字列も置換可能です。


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

//// == Config Retrieving / 工程コンフィグの参照 ==
const strA    = configs.get( "conf_StrA" )    + ""; // required
const strSub  = configs.get( "conf_StrSub" )  + ""; // required
const strNew  = configs.get( "conf_StrNew" )  + ""; // required
const dataIdD = configs.get( "conf_DataIdD" ) + ""; // required
engine.log( " AutomatedTask Search: " + strSub );
engine.log( " AutomatedTask Replacement " + strNew );


//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing, except Expression Language config)


//// == Calculating / 演算 ==
// Escaping for a literal string search
// For a wider range of values, comment out and use Patterns with special characters
let myMatch = new RegExp( strSub
                          .replace(/[.*+?^=!:${}()|[\]\/\\]/g, '\\$&')
                          , 'g' ); // global match
let strOutput = strA.replace( myMatch, strNew );


//// == ワークフローデータへの代入 / Data Updating ==
engine.setDataByNumber( dataIdD, strOutput );

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

Download

Capture

Replaces all the search strings by the replacement string. All matches are case sensitive. For example, it is possible to completely replace the string "XXXX-XX-XX" in the template text with "2020-05-11".

Notes

  1. Regular expressions cannot be used in the search string.
  2. Can also replace strings that include line breaks and tabs.

See also

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: