const regex = new RegExp('\\b(?:(?:m(?:[^A-Za-z]|&\\w+;)*)+(?:o(?:[^A-Za-z]|&\\w+;)*)+(?:t(?:[^A-Za-z]|&\\w+;)*)+(?:h(?:[^A-Za-z]|&\\w+;)*)+(?:e(?:[^A-Za-z]|&\\w+;)*)*(?:r(?:[^A-Za-z]|&\\w+;)*)+)?(?:f(?:[^A-Za-z]|&\\w+;)*)+(?:u(?:[^A-Za-z]|&\\w+;)*)+(?:(?:[^A-Za-z]|&\\w+;)*[ck])+(?<!fuck)(?<!fuk)(?:[^A-Za-z]|&\\w+;)*(?:(?:i(?:[^A-Za-z]|&\\w+;)*)+(?:n(?:[^A-Za-z]|&\\w+;)*)+(?:g(?:[^A-Za-z]|&\\w+;)*)+|(?:e(?:[^A-Za-z]|&\\w+;)*)+(?:[rd](?:[^A-Za-z]|&\\w+;)*)+)?(?:s(?:[^A-Za-z]|&\\w+;)*)*\\b', 'gm')
const str = `fuck and fuk should not match, because they are caught by a different regex
fuc
fuuuck
fuccccck
f u c k ers
With nbsp:
f u c k
test
With no width space:
fuck
With _
f__u__ u___u__c__kers123
f1u1c1k
motherfucker should not match, as it's caught in a different regex
motherfuccker
`;
// 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