Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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")
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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")
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading