简体   繁体   中英

Make hubot respond to a multiline message

I have a scenario where I want hubot to parse something. The command would be 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? it seems to be a better solution to use

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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