Python 特定单词的一个匹配项
我在匹配一个单词时遇到问题。我正在制作一个slack bot,但我在使用regex时遇到了一些困难,下面是中断我的程序的代码:Python 特定单词的一个匹配项,python,regex,Python,Regex,我在匹配一个单词时遇到问题。我正在制作一个slack bot,但我在使用regex时遇到了一些困难,下面是中断我的程序的代码: @listen_to(r'(?:\W|^)(CTRG|Viper)(?:\W|$)', re.IGNORECASE) def refme_send(message): sleep(1) answers = ('You\'re not supposed to talk about it.', 'This information is classified!
@listen_to(r'(?:\W|^)(CTRG|Viper)(?:\W|$)', re.IGNORECASE)
def refme_send(message):
sleep(1)
answers = ('You\'re not supposed to talk about it.', 'This information is classified!')
message.send(answers[randrange(0, len(answers))])
这是我在测试时遇到的错误:
Traceback (most recent call last):
File "/home/my_user/.slack/SlackBot/lib/python3.5/site-packages/slackbot/dispatcher.py", line 55, in _dispatch_msg_handler
func(Message(self._client, msg), *args)
TypeError: hello_reply() takes 1 positional argument but 2 were given
谢谢您的帮助。这与第一行的正则表达式有关吗?请尝试
r'(?i)\b(CTRG | Viper)\b'
什么是hello\u回复
?问题仍然存在。但是感谢您提供了这个可选的正则表达式代码!与refme_send()相同,我有许多函数失败,我没有考虑与示例中的函数对应的错误(我的错误)。无论如何,我对refme|u send()有着完全相同的想法,请尝试@listen_to(r'(?I)\b(CTRG|Viper)\b')
。当您想通知用户时,请在注释中添加@
+用户名。这与第一行的正则表达式有关吗?请尝试r'(?i)\b(CTRG | Viper)\b'
什么是hello\u回复
?问题仍然存在。但是感谢您提供了这个可选的正则表达式代码!与refme_send()相同,我有许多函数失败,我没有考虑与示例中的函数对应的错误(我的错误)。无论如何,我对refme|u send()有着完全相同的想法,请尝试@listen_to(r'(?I)\b(CTRG|Viper)\b')
。如果要通知用户,请将@
+用户名添加到注释中。