const regex = /^-{2}\b[a-z][a-z\d]{2,}\b(-{1}[a-z\d]+)*$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^-{2}\\b[a-z][a-z\\d]{2,}\\b(-{1}[a-z\\d]+)*$', 'gm')
const str = `--valid
--th1s-is-also-val1d
--match-this-option-as-well
--9this-is-invalid-because-of-the-leading-digit
--this--is--invalid--because--of--word--wrapping--by--multiple--hyphens
--this-should-also-fail-because-of-the-trailing-hyphen-
-A -g -1 -Ag1 --valid --th1s-is-also-val1d --match-this-option-as-well --9this-is-invalid-because-of-the-leading-digit --this--is--invalid--because--of--word--wrapping--by--multiple--hyphens --this-should-also-fail-because-of-the-trailing-hyphen- --load-file="ReAdMe2.TxT"`;
const subst = ``;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
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