-1

I am making a bot where if someone does !redeem <key> it redeems their key. However, if people put 2 spaces for example between !redeem and their key the bot does not work. Is it possible for regex to catch all spaces between !redeem and the key.

This is my current code

redeemkey = message.content.lower()
if redeemkey.startswith('!redeem'):
    redeemkey = re.sub("!redeem ", "", redeemkey)
popsmoke
  • 75
  • 1
  • 1
  • 6
  • 1
    You are overthinking it, if you ask me. You're trying to replace the prefix and expect the remainder to be the key. Either do a simple split on space and take the last element or do a capture of the last sequence of non-spaces. – VLAZ Apr 07 '20 at 08:07

1 Answers1

0

You can do this by replacing the code snippet as follows:

redeemkey = message.content.lower()
if redeemkey.startswith('!redeem'):
    redeemkey = re.sub("!redeem[ ]*", "", redeemkey)
Tshiteej
  • 121
  • 6