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”.
Configs for this Auto Step
- conf_StrA
- A: Set String *#{EL}
- conf_StrSub
- B: Set Search String *#{EL}
- conf_StrNew
- C: Set Replacement String *#{EL}
- conf_DataIdD
- D: Select STRING DATA for Replaced String (update) *
Script (click to open)
// Script for 'engine type: 3' ("GraalJS standard mode")
// cf 'engine type: 2' renamed from "GraalJS" to "GraalJS Nashorn compatible mode" (at 20230526)
//////// 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()" ////////////////////////////////////////////////////////////////
// Notes:
- Regular expressions cannot be used in the search string.
- Can also replace strings that include line breaks and tabs.
// Notes (ja):
- 検索文字列の設定に正規表現は利用できません。
- 改行コードやタブコードを含む文字列も置換可能です。
Download
- String-Replace-All-2023.xml
- 2023-08-03 (C) Questetra, Inc. (MIT License)
(Installing Addon Auto-Steps are available only on the Professional edition.)
Notes
- Regular expressions cannot be used in the search string.
- Can also replace strings that include line breaks and tabs.
Capture
