简体   繁体   English

使hubot响应多行消息

[英]Make hubot respond to a multiline message

I have a scenario where I want hubot to parse something. 我有一个场景,我希望hubot解析一些东西。 The command would be hubot parse this thing <the content> 该命令将是hubot parse this thing <the content>

The problem is, the content will generally be a long piece of text pasted in and it usually contains newline characters (line breaks). 问题是,内容通常是粘贴的长文本,它通常包含换行符(换行符)。 Here's my regex: 这是我的正则表达式:

/parse this thing (.*\s*)/i

I'm able to get a response just fine, but only the first line of the content is being read in. Is there any way to get him to read the entirety of the pasted content, including all lines? 我能够得到一个很好的回复,但只有内容的第一行被读入。有没有办法让他阅读整个粘贴的内容,包括所有行?

EDIT: 编辑:

Adding a + makes it read the entire pasted content, but only saves the last line: 添加+会使其读取整个粘贴的内容,但只保存最后一行:

/parse this thing (.*\s*)+/i

Figured it out! 弄清楚了! For future reference (I'm bad at regular expressions): 供将来参考(我对正则表达式不好):

/parse this thing ((.*\s*)+)/i

This would also work: 这也有效:

/parse this thing ((.|\s)+)/i

One or more of any character or whitespace 任何字符或空格中的一个或多个

As outlined in How to use JavaScript regex over multiple lines? 正如如何在多行使用JavaScript正则表达式中所述? it seems to be a better solution to use 它似乎是一个更好的解决方案

/parse this thing ([\s\S]+)/i

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

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