const regex = /Number\:\s(?<Number>\d+)[\r\n]Category\:\s(?<Category>.*).*[\r\n].*[\r\n].*[\r\n]What\sis\sthe\sspecific\srole\sor\sfunction\sof\sthis\sserver\?\:\s(?<Function>.*).*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n]Server\sHostname\:\s(?<Hostname>.*).*[\r\n]Server\sAllegiance\:\s(?<Domain>.*).*[\r\n].*[\r\n]Physical\sLocation\:\s(?<Location>.*).*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n]Local\sAdministrators\:\s+([\w\s]+)[\r\n].*[\r\n].*[\r\n]Task\sDescription\:\s(?<Task>.*)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Number\\:\\s(?<Number>\\d+)[\\r\\n]Category\\:\\s(?<Category>.*).*[\\r\\n].*[\\r\\n].*[\\r\\n]What\\sis\\sthe\\sspecific\\srole\\sor\\sfunction\\sof\\sthis\\sserver\\?\\:\\s(?<Function>.*).*[\\r\\n].*[\\r\\n].*[\\r\\n].*[\\r\\n].*[\\r\\n].*[\\r\\n].*[\\r\\n].*[\\r\\n].*[\\r\\n].*[\\r\\n]Server\\sHostname\\:\\s(?<Hostname>.*).*[\\r\\n]Server\\sAllegiance\\:\\s(?<Domain>.*).*[\\r\\n].*[\\r\\n]Physical\\sLocation\\:\\s(?<Location>.*).*[\\r\\n].*[\\r\\n].*[\\r\\n].*[\\r\\n].*[\\r\\n]Local\\sAdministrators\\:\\s+([\\w\\s]+)[\\r\\n].*[\\r\\n].*[\\r\\n]Task\\sDescription\\:\\s(?<Task>.*)', 'g')
const str = `Task # 12347859 has been opened and assigned to XXXXXXX - .
Task # 12347859
Client Details
Jackie Newman
servicedesk@thenet.com
Assignment Details
User course@email.com
Status and Priority Details
Urgency: 4-LOW
Impact: 4-MINOR
Status: Assigned
Task Details
Number: 12347859
Category: Add/Upgrade Server Software
Application: Production Web Server
Linked Record: CR123458756 - 2-Implementation
What is the specific role or function of this server?: XXXXXXXXXXXX
What is the primary application for this server deployment?: XXXXXXXXXXXXX
Provide a detailed description that explains the function or role of the server.: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
It will also be used as a proxy Card Recon scan server to scan application databases
Is this replacing an existing server?: Si
Please explain when will the old server be decommissioned?: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Is this a physical or virtual server?: XXXXXXXXX
What is the required Operating System?: XXXXXXXXX
Patching Schedule: XXXXXXXXX
Environment - Is the server Production, Development or Disaster Recovery?: XXXXXXXXX
Server Hostname: XXXXXXXXX
Server Allegiance: XXXXXXXXX
Will SQL Server be required on this server?: XXX
Physical Location: XXXXXXXXX
Include in Enterprise Backups?: XX
Resource Requirements: RAM: XXXX
Resource Requirements: CPUs: XX
Resource Requirements: Disk [Quantity and Size(s)]: 40GB
Local Administrators: XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
Directories to be excluded from Anti-Virus scanning: None
Additional Comments:
Task Description: XXXXXXXXX
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions