REGEX: remove left of string until special character

Given the following value ora:hashedPassword I want a regex to remove the whole left string until the : so is left with hashedPassword

I am doing the following currently but only accepts one value to replace, in my current scenario, the array value could contain multiple string patterns (ora:value1, org:value2,pfog1r0:value2)

var schemaArr = ['ora:hashedPassword', 'org:DISTRIB_VALUES_OTH', 'org:categoryTrackingLogStats', 'org:champsPersoAutres', 'org:champsPersoBoutique', 'org:deliveryDOLogStats', 'org:ebNotif', 'org:familleTypologie', 'org:filActuNewBox', 'org:lovDevice', 'org:newBoxNotif', 'org:potentielFibre', 'org:tempsSaison', 'pfog1r0:BRIEF_DELIVERY', 'pfog1r0:BRIEF_DELIVERY_DO', 'pfog1r0:BRIEF_DELIVERY_OFFER_RANGE', 'pfog1r0:BRIEF_DELIVERY_TARGET', 'pfog1r0:BRIEF_DELIVERY_TARGET_DO', 'pfog1r0:BRIEF_DELIVERY_TGT_OFRG', 'pfog1r0:OPERATION_PRT_WAVES', 'pfog1r0:OPERATION_TMK_SUPPLIER'];

var arrayLength = schemaArr.length;

for (var i = 0; i < arrayLength; i++) {
  console.log(schemaArr[i], "auto_" + schemaArr[i].replace("org:", '') + "_seq")
}

>Solution :

A regex to replace all characters leading up to the colon could be as simple as /.*?:/

var schemaArr = ['ora:hashedPassword', 'org:DISTRIB_VALUES_OTH', 'org:categoryTrackingLogStats', 'org:champsPersoAutres', 'org:champsPersoBoutique', 'org:deliveryDOLogStats', 'org:ebNotif', 'org:familleTypologie', 'org:filActuNewBox', 'org:lovDevice', 'org:newBoxNotif', 'org:potentielFibre', 'org:tempsSaison', 'pfog1r0:BRIEF_DELIVERY', 'pfog1r0:BRIEF_DELIVERY_DO', 'pfog1r0:BRIEF_DELIVERY_OFFER_RANGE', 'pfog1r0:BRIEF_DELIVERY_TARGET', 'pfog1r0:BRIEF_DELIVERY_TARGET_DO', 'pfog1r0:BRIEF_DELIVERY_TGT_OFRG', 'pfog1r0:OPERATION_PRT_WAVES', 'pfog1r0:OPERATION_TMK_SUPPLIER'];

var arrayLength = schemaArr.length;

for (var i = 0; i < arrayLength; i++) {
  console.log(schemaArr[i], "auto_" + schemaArr[i].replace(/.*?:/, '') + "_seq")
}

Leave a Reply