Here is the example of my string:
or id:bBkeed
or name:Michael
or surname:Kronenberg
Here is the array of different values with same type and I need to create an array of values before colon and after colon.
const afterDOT = splitedValue[index].substring(splitedValue[index].indexOf(':') + 1);
const beforeDOT = splitedValue[index].substring(0, splitedValue[index].indexOf(':'));
afterDOTS.push(afterDOT);
beforeDOTS.push(beforeDOT);
I need do the same but with regex can somebody help me?
You can try that:
([^:\s]+):([^:\s]+)
Explanation
const regex = /([^:\s]+):([^:\s]+)/g;
const str = `id:bBkeed or name:Michael or surname:Kronenberg`;
let m;
var before=[];
var after=[];
while ((m = regex.exec(str)) !== null) {
before.push(m[1]);
after.push(m[2]);
}
console.log(before);
console.log(after);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With