I was trying to match multiple regex pattern on a string to find start and end index.
let str = "I am abinas patra and my email is [email protected]"
let patterns = [
"[a-z]",
"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"
];
let regexObj = new RegExp(patterns.join("|"), "gmi");
let match, indicesArr=[];
while ((match = regexObj.exec(str))) {
let obj = { start: match.index, end: regexObj.lastIndex }
indicesArr.push(obj);
if(!match.index || !regexObj.lastIndex) break;
}
I am getting only 1 object in the indicesArr which is
[
{
"start":0,
"end": 1
}
]
I want all the a-z characters should match and the email should match as well. I tried multiple approach, could not find it.
Here in patterns array, pattern can be any regex, i just took two example.