How to retrieve values from strings using RegEx

Raki 481 Reputation points
2023-02-10T17:09:45.33+00:00

Hello,

i am trying to retrieve values from below strings using Regular Expression in JavaScript. would you be able to help me out please? it would be separate value for Project Number, Project Name, Insurance Type and the Date.

001196 - La Cabana - Ins Boiler and Machinery – 6/1/21.pdf

Var Project Number= 001196

Var Project Name= La Cabana

Var Insurance Type= Ins Boiler and Machinery

Date= 6/1/21

so far i was able to retrieve Project number using below JavaScript. same way i need to retrieve project name, insurance type and Date without hyphens ad pdf.

if (Fidelity == "Ins Fidelity"){
            var projectNumber = fileName.substring(0,6);
        }
        const regex = /[^0-9]/g;
        projectNumber = projectNumber.replace(regex, "");

        builder.SetDocumentMetadata(doc.DocumentId, "Index", "ProjectNumber", projectNumber);
    }

Thanks in advanced!!

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
870 questions
0 comments No comments
{count} votes