Skip to content

Instantly share code, notes, and snippets.

@oaguy1
Created June 3, 2020 23:05
Show Gist options
  • Save oaguy1/de450170f0deff9785a585c126ebde38 to your computer and use it in GitHub Desktop.
Save oaguy1/de450170f0deff9785a585c126ebde38 to your computer and use it in GitHub Desktop.
import re
raw_comment = "I hate u/oaguy1 and u/example123"
reddit_rx = re.compile(r"\b/?u/[\w-]{3,20}\b")
#returns "I hate USERNAME and USERNAME"
masked_comment = re.sub(reddit_rx, lambda x: "USERNAME", raw_comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment