1

I am trying to build a Go regex filter on the phrase: "Kill yourself" for Twitch Streamers, however... I want to make it so it ignores the phrase if someone says "Don't Kill yourself" in the circumstance that the streamer is playing a video game.

Just trying to figure out the prefix to ignore the word "Don't" "dont" and "do not"

This is what I have so far:

\b(?i)kill (your+[\W_]*?self|ur+[\W_]*?self)\b

I know in the circumstance for the hyphenated characters in other languages to avoid those words getting hit I've done this:

[^Pok|se|jalape|chlo|caf](?i)(?:[Çéâêîôûàèùëïüáéíóúñńü¡¿èéìòùÂâÇçĞğÎîİıÖæöŞşÜüÛû₺ßĎ])(?i)

That way it ignores Jalapeńo and Pokémon. This doesn't seem to be the same with what I'm trying to do above

blackgreen
  • 34,072
  • 23
  • 111
  • 129
  • The negated character class `[^Pok...]` doesn't do what you think it does. `[^Pok|e]` matches a single character which is not (newline or) `P` or `o` or `k` or `|` or `e`. This is a common regex beginner FAQ and covered in the [Stack Overflow `regex` tag info page](/tags/regex/info). – tripleee Apr 27 '22 at 06:53
  • 4
    The futility of trying to match natural language with regular expressions should be apparent; now how do you cope with _"do anything except kill yourself"_ or _"you'd better not kill yourself"_ etc etc. – tripleee Apr 27 '22 at 06:55
  • 1
    In cases like here, when lookarounds are not supported, you should use an optional capturing group and analyze the match structure, if Group 1 was matched or not. If it was, the whole match is considered failed. [Here is my answer](https://stackoverflow.com/a/38935027/3832970) to a similar problem. – Wiktor Stribiżew Apr 27 '22 at 07:25

0 Answers0