How to put a variable into a regex check

Possibly an easy one and I may have missed it in the lessons, cant seem to find the answer online.

if I want to check for /example/ in text, but I want example to be a variable, how do I stop the programme seeing ‘example’ as text and see it as the var?

How to use a Variable in Regular Expression pattern in JavaScript