I'm trying to match a string like this: test0,id=28084 type=high,18765003 138456387
And I'm using this regex:
const str = `test0,id=28084 type=high,18765003 138456387`;
console.log(str.match(/\s*([a-zA-Z0-9\-_.]+)\s*,\s*([a-zA-Z0-9\-_.]+\s*=\s*[a-zA-Z0-9\-_.]+\s*)*\s*,\s*([0-9.]+)\s+([0-9]+)\s*/))
But I am not getting the id
part. Just type=high
.
Any help is appreciated.
Edit: I see that I will only get the last capture group. But not stated in the question, I need there to be a dynamic number of fields at that point in the string. I'm wondering if there's some other way to accomplish this.