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

216
Visualizações
Find the number part of a filename if follows a certain pattern

I'm trying to make a script that will search for the words "ph" in the file name and if it will find it, it will store the ph+5 numbers after it.

At my work we give every job a number "ph32545" for example and I just want to check if the file name contains a ph number and store just that part in a variable.

This is what I have managed to do so far, the problem is that I don't know how to extract the ph number:

var doc = app.activeDocument;

var name = doc.name;
if (name.match("ph") == "ph") {alert("C1");}

the alert is just for testing to see if a ph has been found.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Just searching for ph will also give a match if a filename by coincidence contains these two letters. You should use a RegExp to make sure that ph is followed by five digits.

It could look like this: /ph\d{5}/.

The RegExp must have a / first and last. ph is obviously the text string, \d means "any digit" and {5} means "five times". (You could also just have written /ph\d\d\d\d\d/, but that's a little longer.)

If you don't add a g for "global" after the RegExp, the match method only searches for the first match and returns an array where the first item is the found match.

If there isn't a match, the method will return null.

So your example should be like this:

var doc = app.activeDocument;
var name = doc.name;
var match = name.match(/ph\d{5}/);
if (match) alert(match[0]);

Read more about String.prototype.match().

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