313313 "author" : " dostonnabotov"
314314 }
315315 ]
316+ },
317+ {
318+ "categoryName" : " Regular expression" ,
319+ "snippets" : [
320+ {
321+ "title" : " Regex Match Utility Function" ,
322+ "description" : " Enhanced regular expression matching utility." ,
323+ "code" : [
324+ " /**" ,
325+ " * @param {string | number} input" ,
326+ " * The input string to match" ,
327+ " * @param {regex | string} expression" ,
328+ " * Regular expression" ,
329+ " * @param {string} flags" ,
330+ " * Optional Flags" ,
331+ " *" ,
332+ " * @returns {array}" ,
333+ " * [{" ,
334+ " match: '...'," ,
335+ " matchAtIndex: 0," ,
336+ " capturedGroups: [ '...', '...' ]" ,
337+ " }]" ,
338+ " */" ,
339+ " function regexMatch(input, expression, flags = \" g\" ) {" ,
340+ " let regex = expression instanceof RegExp ? expression : new RegExp(expression, flags)" ,
341+ " let matches = input.matchAll(regex)" ,
342+ " matches = [...matches]" ,
343+ " return matches.map(item => {" ,
344+ " return {" ,
345+ " match: item[0]," ,
346+ " matchAtIndex: item.index," ,
347+ " capturedGroups: item.length > 1 ? item.slice(1) : undefined" ,
348+ " }" ,
349+ " })" ,
350+ " }"
351+ ],
352+ "tags" : [" javascript" ," regex" ],
353+ "author" : " aumirza"
354+ }
355+ ]
316356 }
317- ]
357+ ]
0 commit comments