Build modified string ( string with characters only from pattern are taken )
modifiedString = string NEW_LINE for i in range ( len ( string ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if not modifiedString [ i ] in patternSet : NEW_LINE INDENT modifiedString = modifiedString [ : i ] + modifiedString [ i + 1 : ] NEW_LINE DEDENT DEDENT