-1

I'm making a irc lib and I can't seem to match just private messages, it also matches the version string.

REGEX

:(?P<from>.*?)!\S+\sPRIVMSG\s(?P<to>.*?)\s:(?P<msg>.+)

VERSION MATCH

VERSION_STRING: :AkaneSenri1!~AkaneSenr@72A6C9FC.264941B0.A6596FAF.IP PRIVMSG AkaneSenri1 :VERSION
MATCHED: AkaneSenri1', u'AkaneSenri1', u'\x01VERSION\x01
PRIVATE_MESSAGE_STRING: :AkaneSenri1!~AkaneSenr@72A6C9FC.264941B0.A6596FAF.IP PRIVMSG AkaneSenri1 :T
MATCHED: (u'AkaneSenri1', u'AkaneSenri1', u'T') # is what I want

What I'm getting is the version string that that the server sends when you connect. What I need is, when a user sends the bot a PM. (nick/msg)

1 Answers1

0
:(?P<from>.*?)!\S+\sPRIVMSG\s(?P<to>.*?)\s+:(?!VERSION)(?P<msg>.*)$

It's looking for : not followed by VERSION with a negative lookahead (?!...)

See it here: https://regex101.com/r/sQ7eS6/2 (click on the unit tests bit on the left, then run both tests. Or paste your lines into the main bit)

TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87
  • http://pastebin.com/raw/sb5SqVxJ just comment out `import errors` and all the raise statements, it will run. It still does the version. – Michael Borgfield Jun 21 '16 at 17:53
  • @MichaelBorgfield You can't paste an example string which causes you a problem, but you can share your username and password with the world? Hmm. – TessellatingHeckler Jun 21 '16 at 19:11
  • I posted the exact message the server sends, I also gave the complete lib so you would see. Did you want a complete log? – Michael Borgfield Jun 21 '16 at 19:35
  • I have no idea why this isn't working, I did use a website similar to the one you used. I got a positive match, but for whatever reason it doesn't seem to work when applying to the lib. – Michael Borgfield Jun 21 '16 at 19:40