Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

controller.hears not matching regular expressions correctly #80

Closed
markstickley opened this issue Jan 5, 2016 · 5 comments
Closed

controller.hears not matching regular expressions correctly #80

markstickley opened this issue Jan 5, 2016 · 5 comments

Comments

@markstickley
Copy link

Using this code:

controller.hears('set volume (.*)','direct_message,direct_mention,mention', function(bot, message) {
    console.log(message);
});

I get this output:

{ type: 'message',
  channel: 'G0HNQCS23',
  user: 'U0A1H66FJ',
  text: 'set volume 50',
  ts: '1452007099.000065',
  team: 'T09JJJWKZ',
  event: 'direct_mention' }

There is no match property on message, just the text which I suppose does mean that the regex matched even if it didn't parse the brackets.

However if the regex is 'set volume (\d+)' matching the same text doesn't work (which I think it should).

Am I doing something wrong here?

Thanks!

@lunarmayor
Copy link
Contributor

@markstickley I think you have to escape the escape character like:

'set volume (\\d+)'

@markstickley
Copy link
Author

Oh that’s makes sense yes. Because it’s a string and not a regexp like /set volume (\d+)/.

Thanks! I’ll give it a try.

On 6 Jan 2016, at 02:43, Michael Morrissey [email protected] wrote:

@markstickley https://github.com/markstickley I think you have to escape the escape character like:

'set volume (\d+)'

Reply to this email directly or view it on GitHub #80 (comment).

@markstickley
Copy link
Author

OK well that certainly now seems to match as per the regex. However there still doesn't seem to be a match property on the message as mentioned in the readme. Is this inaccurate? Should I parse the message again? Thanks!

@lunarmayor
Copy link
Contributor

@markstickley are you sure you are using version 0.0.5?

@markstickley
Copy link
Author

Ah! Well now you mention it, no I'm not! Did that come out recently?

Sorry about that, I'll update and try again :)

On 8 Jan 2016, at 19:57, Michael Morrissey [email protected] wrote:

@markstickley are you sure you are using version 0.0.5?


Reply to this email directly or view it on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants