@@ -58,6 +63,7 @@
property: {value:"payload"},
from: {value:""},
to: {value:""},
+ reg: {value:false},
name: {value:""}
},
inputs: 1,
@@ -78,6 +84,7 @@
$("#node-input-t").html("with value");
$("#node-from-row").hide();
$("#node-to-row").show();
+ $("#node-reg-row").hide();
$("#node-tip").html("Tip: expects a new property name and either a fixed value OR the full name of another msg.property eg: msg.sentiment.score");
}
if (a === "delete") {
@@ -86,6 +93,7 @@
//$("#node-input-t").html("to");
$("#node-from-row").hide();
$("#node-to-row").hide();
+ $("#node-reg-row").hide();
$("#node-tip").html("Tip: deletes the named property and all sub-properties");
}
if (a === "change") {
@@ -94,7 +102,8 @@
$("#node-input-t").html("replace with");
$("#node-from-row").show();
$("#node-to-row").show();
- $("#node-tip").html("Tip: if it contains can be a regex, likewise replace with can accept regex results. Only works on strings.");
+ $("#node-reg-row").show();
+ $("#node-tip").html("Tip: If contains is a regex, you must escape any special characters. Likewise replace with can accept regex results. Only works on strings.");
}
//if (a === "replace") {
// $("#node-input-todo").html("called");
diff --git a/nodes/core/logic/15-change.js b/nodes/core/logic/15-change.js
index 4866239c0..0a8b53ef6 100644
--- a/nodes/core/logic/15-change.js
+++ b/nodes/core/logic/15-change.js
@@ -22,6 +22,8 @@ function ChangeNode(n) {
this.property = n.property || "";
this.from = n.from || " ";
this.to = n.to || " ";
+ this.reg = n.reg;
+ console.log("Type=",this.reg);
var node = this;
var makeNew = function( stem, path, value ) {
@@ -35,7 +37,15 @@ function ChangeNode(n) {
this.on('input', function (msg) {
if (node.action == "change") {
- node.re = new RegExp(this.from, "g");
+ if (node.reg === false) {
+ this.from = this.from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
+ }
+ //console.log("Regex is:",this.from);
+ try {
+ node.re = new RegExp(this.from, "g");
+ } catch (e) {
+ node.error("Invalid regex: "+this.from);
+ }
if (typeof msg[node.property] === "string") {
msg[node.property] = (msg[node.property]).replace(node.re, node.to);
}