Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!