Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion public/data/javascript.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,45 @@
"author": "dostonnabotov"
}
]
},
{
"categoryName": "Regular expression",
"snippets": [
{
"title": "Regex Match Utility Function",
"description": "Enhanced regular expression matching utility.",
"code": [
"/**",
"* @param {string | number} input",
"* The input string to match",
"* @param {regex | string} expression",
"* Regular expression",
"* @param {string} flags",
"* Optional Flags",
"*",
"* @returns {array}",
"* [{",
"match: '...',",
"matchAtIndex: 0,",
"capturedGroups: [ '...', '...' ]",
"}]",
"*/",
"function regexMatch(input, expression, flags = \"g\") {",
"let regex = expression instanceof RegExp ? expression : new RegExp(expression, flags)",
"let matches = input.matchAll(regex)",
"matches = [...matches]",
"return matches.map(item => {",
"return {",
"match: item[0],",
"matchAtIndex: item.index,",
"capturedGroups: item.length > 1 ? item.slice(1) : undefined",
"}",
"})",
"}"
],
"tags": ["javascript","regex"],
"author": "aumirza"
}
]
}
]
]