const regex = /(.?(?:FROM)\ [a-zA-Z_]+(?:\.[a-zA-Z_]+)?)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(.?(?:FROM)\\ [a-zA-Z_]+(?:\\.[a-zA-Z_]+)?)', 'g')
const str = `SELECT sl.subscription_link_id link_data_id
, sl.subscription_id link_sub_id
, a.adoption_id link_id
, a.date_created link_start_date
, dispatches.bill_charge_id link_charge_id
, dispatches.total_amount link_amount
, dispatches.status link_charge_status
, dispatches.date_created link_charge_date_created
, dispatches.date_modified link_charge_date_modified
, dispatches.bill_fin_instrument_id charge_bill_fin_instrument_id
, dispatches.date_resolved charge_resolved
, dispatches.lp_exp_date charge_lp_exp_date
, a.date_modified link_date_modified
, a.date_created link_date_created
, dispatches.base_price_type_id link_base_price_type_id
, dispatches.status link_bill_charge_status
, CASE
WHEN ls.exp_date IS NOT NULL
THEN ls.exp_date
ELSE add_months(l.date_created, lp.num1 * DECODE(lp.num2,1,12,2,1) )
END link_end_date
, CASE
WHEN ls.exp_date IS NOT NULL
THEN 1
ELSE (lp.num1 * DECODE(lp.num2,1,12,2,1,5,0,0))
END link_term
FROM emetadata.ers_subscription_links sl
, emetadata.ers_adoptions a
, emetadata.ers_adopt_fulfillments af
, emetadata.ers_licenses l
, emetadata.ers_license_parameters lp
, emetadata.ers_license_slots ls
, (SELECT adopt_charge.bill_charge_id
, adopt_charge.status
,adopt_charge.total_amount
, partitions.date_resolved
,partitions.lp_exp_date
, adopt_charge.adoption_id
,adopt_charge.date_created
, adopt_charge.date_modified
, adopt_charge.bill_fin_instrument_id
, adopt_charge.base_price_type_id
FROM
(SELECT bc.bill_charge_id
, bc.status
, bc.date_created
, bc.date_modified
, bc.total_amount
, bc.bill_fin_instrument_id
, acl.adoption_id
,oicl.base_price_type_id
FROM emetadata.ersmd_adoption_charge_link acl
, emetadata.ers_bill_charge bc
, emetadata.ers_order_charge_links oicl
WHERE acl.charge_id = bc.bill_charge_id AND oicl.bill_charge_id = bc.bill_charge_id
) adopt_charge
, (SELECT pcl.bill_charge_id
, bd.date_resolved
, cpi.lp_exp_date
FROM emetadata.ers_bill_dispatches bd
, emetadata.ers_charge_partitions cp
, emetadata.ersmd_charge_partition_info cpi
, emetadata.ers_part_charge_link pcl
WHERE cp.charge_partition_id = bd.charge_partition_id (+) AND cp.charge_partition_id=cpi.charge_partition_id(+) AND cp.charge_partition_id =
pcl.charge_partition_id AND cp.status = 3
) partitions
WHERE adopt_charge.bill_charge_id = partitions.bill_charge_id (+)
) dispatches
WHERE a.subscription_link_id = sl.subscription_link_id AND af.adoption_id = a.adoption_id AND a.adoption_id = dispatches.adoption_id (+) AND
af.fulfillment_target_id = l.license_id AND l.license_id = lp.license_id AND l.license_id = ls.license_id (+);
`;
// 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