title: javascript- replace text with part of the file name
body: <p>I'm trying to create a script in adobe illustrator that will check if a file name contains &quot;ph&quot; +5 numbers.
  If it has been found then it will replace a part of a text with the match from the file name.</p>
  <p>This is what I have so far I just can't get it to work, the text is replaced with &quot;null&quot;</p>
  <pre><code>var doc = app.activeDocument;
  
  var name = doc.name;
  var match = name.match(/ph\d{5}/);
  
  for (i = 0; i &lt; doc.textFrames.length; i++)
  {
      doc.textFrames[i].contents = doc.textFrames[i].contents.replace(/ph00000/gi, match);
  }
  </code></pre>