const regex = /^\w+(\s\w&\w)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\w+(\\s\\w&\\w)', 'gm')
const str = `Employee Communications & Engagement, WB
SVP of Global Insights & Analytics, WB
SVP of Nonfiction, HBO Max
VP of Talent Relations and Development, TCM
Global Franchise Management, DC
WB Technology Group
President, EMEA & APAC
SVP & CFO, EMEA & APAC
Director, Service Delivery
SVP for Sales and Client Partnerships, Legacy Turner
Technical Director, WarnerMedia
Dir. of Brand Distribution, WarnerMedia
Dir. Strategic & Consumer Insights, Turner Sports
Manager for Digital Asset & Photo Library, Brand Experience
Creative Manager for Creative Services, Cartoon Network
// 2 words
Cincinnati Bearcats
Miami (FL) Hurricanes
Miami (OH) Redhawks
// three words
South Florida Bulls // 2.1
Saint Joseph's Hawks
Duke Blue Devils // 1.2
UNLV Runnin' Rebels // with apostrophe
// 4 words
North Carolina Tar Heels
Notre Dame Fighting Irish
St John's Red Storm
Florida A&M Rattlers
William & Mary Tribe
St Francis (PA) Red Flash
`;
// 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