简体   繁体   English

Hubot 不响应正则表达式

[英]Hubot Not Responding to regex

I am working on a hubot slack integration, but have hit a bit of a brick wall.我正在研究 hubot 松弛集成,但遇到了一些障碍。 I am trying to get hubot to respond to this regex我正在尝试让 hubot 响应此正则表达式

(\d{4}\-){3}\d{4}

But for some reason it will not work.但由于某种原因它不起作用。

Code Snippet代码片段

robot.respond /(\d{4}\-){3}\d{4}/i, (msg) ->
    msg.send "Words, Words, Words"

Any help would be greatly appreciated.任何帮助将不胜感激。

Regards, Austin问候, 奥斯汀

In Hubot, the respond regex is anchored , so the whole string should match.在Hubot,该respond正则表达式是固定的,所以整个字符串应该匹配。

Thus, you need to either add .* or [\\s\\S]* on both ends of the regex.因此,您需要在正则表达式的两端添加.*[\\s\\S]* Also, I recommend to add word boundaries \\b to make sure you match a whole word.另外,我建议添加单词边界\\b以确保匹配整个单词。

Thus, if there are newline symbols in the input, use因此,如果输入中有换行符,请使用

/[\s\S]*\b(\d{4}\-){3}\d{4}\b[\s\S]*/

If there are no newline symbols, just use如果没有换行符,只需使用

/.*\b(\d{4}\-){3}\d{4}\b.*/

Note the the case insensitive modifier is redundant here as there are no letters in the pattern.注意不区分大小写的修饰符在这里是多余的,因为模式中没有字母。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM