const regex = /@param\s+\{\(?([^}]+)\)?\}\s+(\[.+\]|[\w]+(?:\[.+\])?)\s+([\s\S]*?)(?=\@|\*\/)/gim;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('@param\\s+\\{\\(?([^}]+)\\)?\\}\\s+(\\[.+\\]|[\\w]+(?:\\[.+\\])?)\\s+([\\s\\S]*?)(?=\\@|\\*\\\/)', 'gim')
const str = `/**
* Removes elements from \\\`array\\\` corresponding to \\\`indexes\\\` and returns an
* array of removed elements.
*
* **Note:** Unlike \\\`_.at\\\`, this method mutates \\\`array\\\`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to modify.
* @param {...(number|number[])} [indexes] The indexes of elements to remove,
* specified individually or in arrays.
* @returns {Array} Returns the new array of removed elements.
* @example
*
* var array = [5, 10, 15, 20];
* var evens = _.pullAt(array, 1, 3);
*
* console.log(array);
* // => [5, 15]
*
* console.log(evens);
* // => [10, 20]
*/
var pullAt = rest(function(array, indexes) {
indexes = arrayMap(baseFlatten(indexes), String);
var result = baseAt(array, indexes);
basePullAt(array, indexes.sort(compareAscending));
return result;
});`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions