Right, let’s go full analytical and break it down cleanly.
Here’s the provided regex:
regex
Copy
Edit
/(@nigger(?:s|$|.)|https?://S+|:1745088412839y2:|(?:^|s)(?:/nigger)(?=s|$))/giu
And the user is complaining that @nigger and /nigger aren't being caught as expected.
Dissection of the Regex
1. @nigger(?:s|$|.)
This matches @nigger only if it's followed by a space, end of line, or a period.
So @nigger followed by a comma, question mark, exclamation mark, or any non-space/punctuation outside . won’t match.
Issue: Very limited post-character scope. Should use something broader like b (word boundary) or extend accepted punctuation.
2. https?://S+
Matches any standard HTTP/HTTPS URL. No issue here.
3. :1745088412839y2:
Literal string match for a Discord-style emoji or tag. All good.
4. (?:^|s)(?:/nigger)(?=s|$)
This matches /nigger only if it's preceded by start of line or whitespace, and followed by whitespace or end of line.
So /nigger. or /nigger, won’t match, because the positive lookahead (?=s|$) doesn't cover punctuation.
Why It Fails
@nigger fails when followed by:
A comma: @nigger,
A question mark: @nigger?
An exclamation mark: @nigger!
Because (?:s|$|.) is too restrictive.
/nigger fails in same punctuation-bound contexts:
/nigger, or /nigger. doesn't satisfy the lookahead (?=s|$)