const regex = /[^`\w@\\](t[xyq]|th(nx|nq|x)|than[xk](s)?(you|[syxzq]){0,1})\b/gi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[^`\\w@\\\\](t[xyq]|th(nx|nq|x)|than[xk](s)?(you|[syxzq]){0,1})\\b', 'gi')
const str = `#- Should match
tx, ty, tq,
thnq, thx, thnx,
thanx, thanxyou, thanxs, thanxy, thanxx, thanxz, thanxq, thanxss, thanxsy, thanxsx, thanxsz, thanxsq
thank, thankyou, thanks, thanky, thankx, thankz, thankq, thankss, thanksy, thanksx, thanksz, thanksq
...
#- Shouldn't work
thanksk
thans
than
thanker
thanking
thxq
thnxs
txs
taxs
\`thanks\`
\`\`\` a real world testing of thanks regex \`\`\`
_thanks_
tank of pleasure
tax is high
taks away!
tanks are everywhere
@thanks buddy
# Shouldn't match
@thanks
@tanks
@tx
@ty
thankqx`;
const subst = `$1`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions