const regex = new RegExp('\\((?:[^)(]+|\\((?:[^)(]+|\\([^)(]*\\))*\\))*\\)', 'gm')
const str = `Financial Operations (Financing, Customer Payment, and Settlement (AR), Collaborative Financial Processing, Vendor Invoice Verification and Processing (AP),Bank processes and Relationship Management, Allocation of Shared Services), Accounting(Financial statements, General Ledger and Subledger, Revenue and Cost Accounting, Job and Product Accounting, Product and Service Costing ), Corporate Services (Real estate management, Travel management (TEAs), Treasury and finance management ) Human Resource Management (HR Strategy and Planning, Recruitment, Payroll, Compensation and Total Benefits, Employee Development ), Manufacturing and Logistics (Production planning, materials management, inventory management, order entry and processing, warehouse mgmt, transportation mgmt, project mgmt, plant maintenance, customer service mgmt)`;
// 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