Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

306
Visualizações
javascript- replace text with part of the file name

I'm trying to create a script in adobe illustrator that will check if a file name contains "ph" +5 numbers. If it has been found then it will replace a part of a text with the match from the file name.

This is what I have so far I just can't get it to work, the text is replaced with "null"

var doc = app.activeDocument;

var name = doc.name;
var match = name.match(/ph\d{5}/);

for (i = 0; i < doc.textFrames.length; i++)
{
    doc.textFrames[i].contents = doc.textFrames[i].contents.replace(/ph00000/gi, match);
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can encapsulate the text that you want to replace with group constructs, and since you're using String.prototype.replace, you can capture the parenthesized group and pass the callback function as the 2nd argument in your .replace function.

regex replace table

Read more about it here

Example:

const textString = "This is ph54321 or ph12345";

const newString1 = textString.replace(/(ph)\d{5}/gi, function (matches, p1) {
    return p1 + "appended"; // "This is phappended or phappended"
});

const newString2 = textString.replace(/ph(\d{5})/gi, function (matches, p1) {
    return "BIGPH" + p1; // "This is BIGPH54321 or BIGPH12345"
});

console.log({newString1});
console.log({newString2});

about 4 years ago · Juan Pablo Isaza Relatório

0

I'd try this:

var doc = app.activeDocument;

var match = doc.name.match(/ph\d{5}/);

if (match != null) {
  for (i = 0; i < doc.textFrames.length; i++) {
    doc.textFrames[i].contents = doc.textFrames[i].contents.replace(/ph00000/gi, match[0]);
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda