-4

Let's say the user is allowed the enter a string like this

hello how are you I am a bad boy

Now let's say we have to detect for profanity against an array of bad words

bad
long neck
abc
def
...

I want to be able to detect if the user enters in bad, but if they said baddie that's ok. And it's not just spaces, but also other punctuation is allowed to break up the words. For example:

I am a baddie //pass
I am a bad,die //fail
I am a bad die //fail
I have a longneck //pass
I have a long neck //fail
I have a long, neck //pass
I have a neck long //pass

How can this be done in swift?

erotsppa
  • 14,248
  • 33
  • 123
  • 181
  • 3
    You should research regex – jnpdx Aug 28 '23 at 05:35
  • Definitely possible. Yes/no questions aren't really permitted on StackOverflow though. – Jeppe Aug 28 '23 at 05:35
  • See https://stackoverflow.com/questions/32168581/split-paragraphs-into-sentences - answers are easily tweaked to get words. – HangarRash Aug 28 '23 at 05:50
  • https://developer.apple.com/documentation/naturallanguage/tokenizing_natural_language_text – lorem ipsum Aug 28 '23 at 11:47
  • @HangarRash why does that question get +3 votes, and this -4, elites makes SO completely useless now – erotsppa Aug 28 '23 at 15:03
  • If I had to speculate about the downvotes (I'm not one of them), I'd guess it's because you didn't list anything about your research or attempts. However, the linked question suffers from the same issue. – jnpdx Aug 28 '23 at 15:05
  • @erotsppa That other question is 8 years old. I guess the standards were different then. If you hover your mouse over the downvote button, the tooltip that appears begins with *"This question does not show any research effort"*. Your question does seem to fit that as written. – HangarRash Aug 28 '23 at 15:26

0 Answers0