Skip to main content
BEGINNER_X
Legend
October 16, 2015
Answered

Find Job Number in file path

  • October 16, 2015
  • 2 replies
  • 575 views

Hi,

I need to find the Job Number only stored in variable.

In the below file path, I need the 8 digit number only(98456357, 88456656, 98456357)

Sample file path are below:

/Users/Shared/Siraj/98456357_Octt/ENL.indd

/Users/Shared/Siraj/88456656_Octt/Document/PHL.indd

/Users/Shared/Siraj/98456357_Octt/Document/Check/PHL.indd

var myFilePath = app.activeDocument.filePath

Thanks in Advance

Siraj

This topic has been closed for replies.
Correct answer Ronald63

Hi,

Here's an example of what we can do with a regular expression

var myPath ='/Users/Shared/Siraj/98456357_Octt/Document/Check/PHL.indd';

var mJobNumber;

var reg = /(\/)([0-9]{8})(_)/;

if (myPath.match(reg)){

    mJobNumber = RegExp.$2;

    alert(mJobNumber)

}

Regards

2 replies

Ronald63Correct answer
Legend
October 16, 2015

Hi,

Here's an example of what we can do with a regular expression

var myPath ='/Users/Shared/Siraj/98456357_Octt/Document/Check/PHL.indd';

var mJobNumber;

var reg = /(\/)([0-9]{8})(_)/;

if (myPath.match(reg)){

    mJobNumber = RegExp.$2;

    alert(mJobNumber)

}

Regards

BEGINNER_X
Legend
October 16, 2015

Great Ronald.. working good.

Thanks vamitul....

Vamitul
Legend
October 16, 2015

Well, first convert the file path to a string, the use a regular expression on it to get the number:
https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions