Where to add add_rewrite_tag for trailing tilde?

Ive just been reading @gmazzap s reply about wordpress matching URLs with trailing tildes.

and could do with some help please. As a coding newbie, I am not sure where to add his suggested code:

Functions.php, /includes/rewrite.php, or somewhere else…

Also what are the implications of doing this, when wordpress updates, will these changes be lost? Am running a child theme.
Sorry to ask such basic questions. Thanks for your help.