Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Search and replace item in array ?

  • Search and replace item in array ?

    Posted by Shai Benshoshan on March 19, 2018 at 4:22 pm

    Probably there is a better way to do it:
    I am trying to replace all the instances of a specific font in an array :

    This method is working to find “Roboto” and replace it with “Open Sans”

    toSort = [“Verdana”, “Roboto”, “Times New Roman”, “Verdana”, “Roboto”];
    var str = toSort.toString();
    var patt1 = /Roboto/;
    var result = str .replace(str.match(patt1), “Open Sans”);
    alert(result);

    Whan I try to search globally (var patt1 = /Roboto/g;) it’s not working at all (not finding “Roboto” at all );

    My final goal is to set the search word and the replace word as array elements :
    this is not successful at all for me :

    Thank you for any help or idea


    toSort = ["Verdana","Roboto","Times New Roman","Verdana", "Roboto"];
    desFont = ["Exo2","Open Sans"];

    var str = toSort.toString();
    var src = toSort[0].toString();
    var rplc = desFont[0].toString();

    var patt1 = /src*/g;
    var result = str .replace((str.match(patt1)), rplc);
    alert( result);

    Shai Benshoshan replied 8 years, 2 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy