const regex = /^(Primary|Secondary|Tertiary).Gene:.([A-Z]|[a-z])+ \(1\)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(Primary|Secondary|Tertiary).Gene:.([A-Z]|[a-z])+ \\(1\\)', 'gm')
const str = `1([A-Z]|[a-z])+
Scroll of Renaming (1)
Seller: Rogrinus
Expires in: 07 hr, 09 min, 46 sec
Selling price:
200000
1
Secondary Gene: Loop (Veilspun) (1)
Seller: Natta
Expires in: 09 hr, 21 min, 47 sec
Selling price:
200000
1
Primary Gene: Python (1)
Seller: PlatinumStardust
Expires in: 1 days, 07 hr, 37 min, 50 sec
Selling price:
200000
1
Primary Gene: Stitched (Veilspun) (1)
Seller: lizagem
Expires in: 2 days, 11 hr, 07 min, 56 sec
Selling price:
200000
1
Primary Gene: Stitched (Veilspun) (1)
Seller: ScarletCyanide
Expires in: 3 days, 06 hr, 31 min, 26 sec
Selling price:
200000
1
Tertiary Gene: Capsule (Veilspun) (1)
Seller: forcipiger
Expires in: 4 days, 04 hr, 15 min, 26 sec
Selling price:
200000
1
Tertiary Gene: Firefly (Veilspun) (1)
Seller: Pyracantha
Expires in: 4 days, 23 hr, 35 min, 53 sec
Selling price:
200000
1
Primary Gene: Python (1)
Seller: sisyo
Expires in: 5 days, 13 hr, 59 min, 20 sec
Selling price:
200000
1
Tertiary Gene: Squiggle (Banescale) (1)
Seller: BananaMeteor
Expires in: 5 days, 18 hr, 32 min, 31 sec
Selling price:
200000
1
Primary Gene: Skink (1)
Seller: H0ur
Expires in: 6 days, 13 hr, 07 min, 31 sec
Selling price:
200000
`;
// 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