const regex = /@(\S+) (\S+) (\S+(?: -> \S+)*) ?((?:(?!\*\/).)*)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('@(\\S+) (\\S+) (\\S+(?: -> \\S+)*) ?((?:(?!\\*\\\/).)*)', 'gm')
const str = `/**
* Class Object
* @package Model\\Example\\Objects
* @property-read int id
* @property order_id
* @property string|NULL external_order_id -> externalOrderId
* @property string order_source
* @property int order_source_id
* @property string order_source_info foo, foo, bar.
* @property int order_status_id
* @property int date_add
* @property int date_confirmed
* @property int date_in_status
* @property string user_login
* @property string phone
* @property string email
* @property array products 21 foobar*/`;
// 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