Python Regex for ignoring a sentence with two consecutive upper case letters
Question: I have a simple problem at hand to ignore the sentences that contain two or
more consecutive capital letters and many more grammar rules .

**Issue:** By the definition the regex should not match the string `'This is
something with two CAPS.'` , but it does match.

**Code:**

    
    
    ''' Check if a given sentence conforms to given grammar rules
    
        $ Rules
            * Sentence must start with a Uppercase character (e.g. Noun/ I/ We/ He etc.)
            * Then lowercase character follows.
            * There must be spaces between words.
            * Then the sentence must end with a full stop(.) after a word.
            * Two continuous spaces are not allowed.
            * Two continuous upper case characters are not allowed.
            * However the sentence can end after an upper case character.
    '''
    
    import re
    
    
    # Returns true if sentence follows these rules else returns false
    def check_sentence(sentence):
        checker = re.compile(r"^((^(?![A-Z][A-Z]+))([A-Z][a-z]+)(\s\w+)+\.$)")
        return checker.match(sentence)
    
    print(check_sentence('This is something with two CAPS.'))
    

**Output:**

    
    
    <_sre.SRE_Match object; span=(0, 32), match='This is something with two CAPS.'>
    


Answer: It’s probably easier to write your regex in the negative (find all sentences
that are bad sentences) than it is in the positive.

    
    
    checker = re.compile(r'([A-Z][A-Z]|[ ][ ]|^[a-z])')
    check2 = re.compile(r'^[A-Z][a-z].* .*\.$')
    return not checker.findall(sentence) and check2.findall(sentence)
    

