Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

301
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda