variable parsing into regex - what is the trick?
Posted: July 24th, 2013, 8:50 pm
I have been trying to figure this out for hours. What is the trick to getting a variable into a regular expression:
(regular expression searching for string: fur)
(full code below)
this works fine:
but when I try to parse a variable it doesn't work:
I have tried a variety of searchStringer's like the var having just the string ('fur'), and then
and also
and
but to no avail - am I missing something?
whole code here:
(this is the line you can change to get it to work:)
var itemIndexifReturned = (layer.search(searchStringer,""));
to
var itemIndexifReturned = (layer.search(/fur/gi,""));
code not cleaned yet ![Smile :)](./images/smilies/icon_smile.gif)
(regular expression searching for string: fur)
(full code below)
this works fine:
Code: Select all
var itemIndexifReturned = (layer.search(/fur/gi,""));
alert (itemIndexifReturned);
Code: Select all
var searchStringer = '/fur/gi';
var itemIndexifReturned = (layer.search(searchStringer,""));
alert (itemIndexifReturned);
Code: Select all
.search(/searchStringer/gi,"")
Code: Select all
.search(/+searchStringer+/gi,"")
Code: Select all
.search("/"+searchString+"/gi","")
whole code here:
(this is the line you can change to get it to work:)
var itemIndexifReturned = (layer.search(searchStringer,""));
to
var itemIndexifReturned = (layer.search(/fur/gi,""));
Code: Select all
// code will eventually loop all layers in current comp, then we can do something to each layer that has a matching search string
//the script will ask user for search string, like fur, occ, bg, col etc...
// for the sake of other peoples searches... this script remembers (stores) the last input and recalls and inserts it the next time the script is run.
var title = ("color layers by");
var firstVal = "Fur";
if (app.settings.haveSetting("jono", title)==false) app.settings.saveSetting("jono", title, firstVal);
var layers = app.project.activeItem.layers; // Retrieve the composition's layers
var layer;
//var searchString = prompt("Search by:",app.settings.getSetting("jono", title),title);
//if (searchString != null) app.settings.saveSetting("jono", title, searchString);
var searchStringer = '/fur/gi';
//alert (searchStringer);
for (var i = 1; i <= layers.length; i++) {
layer = layers[i].name;
alert(layer);
//alert((layer).match(searchStringer)[1]);
var itemIndexifReturned = (layer.search(searchStringer,""));
alert(itemIndexifReturned);
//var itemIndexifReturned = (searchStringer.search(layer))
if (itemIndexifReturned!= -1) {
layers[i].blendingMode = BlendingMode.MULTIPLY; // test if working
}
}
![Smile :)](./images/smilies/icon_smile.gif)