const regex = /\b(?:[^\W_]+_[^\W_]+ )?(?<!_PN |_PN1 |_PNQ[OVS] |_PNX1 |_PPGE |_PPH1 |_PPHO[12] |_PPHS2 |_PPIO[12] |_PPIS[12] |_PPX[12] |_PPY )[^\W_]*_V\w*/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\b(?:[^\\W_]+_[^\\W_]+ )?(?<!_PN |_PN1 |_PNQ[OVS] |_PNX1 |_PPGE |_PPH1 |_PPHO[12] |_PPHS2 |_PPIO[12] |_PPIS[12] |_PPX[12] |_PPY )[^\\W_]*_V\\w*', 'gm')
const str = `Ya_UH and_CC then_RT uhm_NN1 we_PPIS2 wrote_VVD in_RP but_CCB already_RR taken_VVN up_RP that_DD1 day_NNT1 that_CST we_PPIS2 wanted_VVD actually_RR they_PPHS2 said_VVD still_RR available_JJ you_PPY know_VV0 so_RR by_II that_DD1 time_NNT1 we_PPIS2 we_PPIS2 write_VV0 in_II our_APPGE letter_NN1 two_MC weeks_NNT2 later_RRR already_RR taken_VVN up_RP Quite_RG good_RR uh_UH P ICE-SIN:S1A-001#74:1:B Ask_VV0 her_PPHO1 I_PPIS1 left_VVD my_APPGE house_NN1 at_II one_MC1 met_VVD PRO_NN1 in_II school_NN1 at_II two_MC Ya_PPY so_RR waited_VVD you_PPY know_VV0 they_PPHS2 say_VV0 half_DB hour_NNT1 later_RRR And_CC and_CC it_PPH1 was_VBDZ still_RR drizzling_JJ and_CC raining_VVG
`;
// 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