You work for a social media platform, and are told to create a program in a language of your choice that will automatically flag certain post titles as "spam".
Your program must take the title as a string as input and output a truthy value if the title is spam, and a falsey value if not.
To qualify as non-spam, a title must conform to the following rules, otherwise it is spam:
- A title can only contain spaces and the following characters: a-z, A-Z, 0-9,
-
,_
,.
,,
,?
,!
- A title cannot have more than one Capital Letter per word
- A title cannot have more than one exclamation mark or question mark
- A title cannot have more than three full-stops (
.
) - A title cannot have more than one comma (
,
)
Test cases:
Input: How On eaRth diD tHis happeN
Output: False
Input: How on earth did this happen 🔊
Output: True
Input: How ON earth did this happen
Output: True
Input: How on earth did this happen??
Output: True
Input: How on earth did this happen?!
Output: True
Input: How on earth did this happen!!
Output: True
Input: How! on! earth! did! this! happen!
Output: True
Input: How on earth did this happen! !
Output: True
Input: How on earth did this happen?
Output: False
Input: How on earth did this happen!
Output: False
Input: How on earth did this happen...
Output: False
Input: How.on.earth.did.this.happen
Output: True
Input: How.on.earth.did this happen
Output: False
Input: How, on, earth did this happen
Output: True
Input: How, on earth did this happen
Output: False
Input: How_on_earth_did_this_happen
Output: False
Input: How-on-earth-did-this-happen
Output: False
Input: How on earth did (this) happen
Output: True
Input: How on earth did "this" happen
Output: True
Input: How on earth did 'this' happen
Output: True
Input: How on earth did *this* happen
Output: True
Input: How on earth did [this] happen
Output: True
FAQ
Q: What is a valid title?
A: Single-character titles are valid. Your program has to validate a string that is not completely whitespace against the bullet-point rules above.
Q: What is a word?
A: Split the title string by a space. Each item in the resulting array is considered a word.
This is code-golf, so the shortest answer in bytes wins.
这到底怎么回事
Most regexp based answers which support Unicode would be confused if\w
is used. \$\endgroup\$