Sanitizing user comment entries text field help

If you can standardize on a single replace character, the regex becomes simpler.

import re

Comments = self.parent.parent.getChild("topspacer flex_5").getChild("TextField_0").props.text

pattern = re.compile('[^a-zA-Z0-9 -]')

Comments = pattern.sub('', Comments)
3 Likes