Hi i have a problem in finding exact regex to solve my problem
I have key which contains :// which means string may continue //
As said above
string will continue after // so below case is not matching
getMatchingObj('bins/fs://retrieve/user');
here is what i have tried:
var pinfoObj = {
['bins/fs://']:{name:'bins',otherinfo:{}},
['library']: {name:'library',otherinfo:{}},
['library/nr']:{name:'nr',otherinfo:{}},
['gt']:{name:'gt',otherinfo:{}}
};
function getMatchingObj(pstr){
var pattern = new RegExp(`^${pstr}(\/(\w*\S+))?`, 'ig');
for(var key in pinfoObj){
if(pattern.test(key)){
return pinfoObj[key];
}
}
}
console.log(getMatchingObj('bins/fs://retrieve/user')); // doesnot match, my string continues after // which is retrieve/user - my intention match this too with above regex
console.log('this works but extact cant be there in real case',getMatchingObj('bins/fs://'));
console.log(getMatchingObj('library/nr')); // matches
console.log(getMatchingObj('gt')); // matches
here is what i have tried to match all the test cases but in vain
regex101.com: https://regex101.com/r/3vKZVW/2
Expected Output: with the expected key i should not get un-expected value or all the 4 given test cases should match
please help me thanks in advance!!