def filterStringValue(value, charRegex, replacement=''):
 retVal = value
 if value:
  retVal = re.sub((charRegex.replace('[', '[^') if ('[^' not in charRegex) else charRegex.replace('[^', '[')), replacement, value)
 return retVal

def filterStringValue ( value , charRegex , replacement = '' ) : retVal = value if value : retVal = re . sub ( ( charRegex . replace ( '[' , '[^' ) if ( '[^' not in charRegex ) else charRegex . replace ( '[^' , '[' ) ) , replacement , value ) return retVal
returns string value consisting only of chars satisfying supplied regular expression .