const regex = /\.populate_tasks\[(arc|buck|build|hg|phabricator|source_control),/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\.populate_tasks\\[(arc|buck|build|hg|phabricator|source_control),', 'gm')
const str = `── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,diff]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,fix]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,focus]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,lint]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,pull]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[arc,refocus]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[buck,build]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[buck,install]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[buck,project]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[buck,run]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[buck,test]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,arc_rebuild]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,buck_build]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,entschema]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,fbios_noextensions]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,instagram_ios_noextensions]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,messenger_ios_noextensions]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,multifeed]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,unicorn]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,wakizashi]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[build,wakizashi_s2p]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[devserver,arc_fix]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[devserver,fixmyserver]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[devserver,flow_oom]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[devserver,hack_oom]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[devserver,hhserver_oom]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hack,hh_healthy_minutes]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,amend]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,bookmarks]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,branch]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,commit]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,diff]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,log]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,pull]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,rebase]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,smartlog]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,status]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[hg,update]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,flow_check]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,flow_init]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,hh_full_check]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,hh_lazy_check]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,hh_server_init]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,intellij_file_to_intellisense]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[ide,intellij_project_to_intellisense]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[land,clean_lands]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[land,landcastle]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,diffusion_pageload]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,gql_client_duration]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,gql_mutation_duration]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,jf_submit_set_dependencies]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,jf_submit_set_diffproperty]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,jf_submit_total_elapsed]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,jf_submit_update_diff]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[phabricator,jf_submit_update_revision]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[presto,adhoc_queue]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[source_control,hg]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[source_control,jellyfish]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[test,local_www]
── infrastructure.devspeed.error_rates.devspeed_raw_cost_events.populate_tasks[test,mobilelab]`;
// 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