CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
possible regex problem, not matching

 



fatalnix
New User

Oct 19, 2008, 3:08 PM

Post #1 of 7 (5434 views)
possible regex problem, not matching Can't Post

Hi, I have a strange problem. You see, Though I am aware of modules such as POE::Component::IRC and such, I am writing an IRC bot with IO::Socket because I find it to be much more involved, and I needed something that I had complete control over as well as learn the RFC for IRC and concentrate on improving my regex skills. I was unsure either to put this under beginner or regex so please don't flame me for this, I'm unsure of the true problem but think it may be something to do with it-

I made two scripts, one that takes a regex line into an if statement with an actual example, to check that my regex matches correctly, the regex was simply copied and pasted t ensure they were the same.. The test script returns that the regex in fact does match. but in the irc bot script, when it recieves the data, it does not.

(I looked for any posts regarding rules to see if I'm not supposed to put in links, but did not see anything, so please redirect me if I am mistaken)
I sent it to pastebin so it didnt spam 2 pages of the forum:

http://pastebin.com/d2e93505c

I will be happy for anyone who tries to help.

Edit: I forgot to mention something possibly important, the end of /motd regex works and the ident one does, but not join or both privmsg's


(This post was edited by fatalnix on Oct 19, 2008, 3:09 PM)


KevinR
Veteran


Oct 19, 2008, 3:17 PM

Post #2 of 7 (5431 views)
Re: [fatalnix] possible regex problem, not matching [In reply to] Can't Post

this:


Code
	if ($data =~ /^:(\w+)!\w+(\@|\-)[\w\.]+ PRIVMSG $irc_nick :(.*)/ ) { 
my ($nick, $chan, $msg) = ($1, $3, $4);


looks like it should be:


Code
	if ($data =~ /^:(\w+)!\w+(\@|\-)[\w\.]+ PRIVMSG $irc_nick :(.*)/ ) { 
my ($nick, $chan, $msg) = ($1, $2, $3);

-------------------------------------------------


fatalnix
New User

Oct 19, 2008, 3:27 PM

Post #3 of 7 (5430 views)
Re: [KevinR] possible regex problem, not matching [In reply to] Can't Post

the reason for $1, $3, and $4 is because $2 is either @ or -, since the irc server I'm connected to is sometimes - and sometimes its reported as @, but if I removed the ()'s from (\@|\-) would that still work?

here is an example format of the irc server output in which the join regex would match, if it helps:

:nickname!theiruser@example.host.mydsl.com JOIN :#channel


(This post was edited by fatalnix on Oct 19, 2008, 3:31 PM)


KevinR
Veteran


Oct 19, 2008, 3:46 PM

Post #4 of 7 (5426 views)
Re: [fatalnix] possible regex problem, not matching [In reply to] Can't Post

That would match against another regexp:


Code
	if ($data =~ /^:(\w+)!\w+(\@|\-)[\w\.]+ JOIN :(#\w+)$/ ) { 
my ($nick, $chan) = ($1, $3);
print "CAUGHT JOIN\n";
}


And you notice it uses $1 and $3.

$2 would be the @|- match.
-------------------------------------------------


KevinR
Veteran


Oct 19, 2008, 3:50 PM

Post #5 of 7 (5424 views)
Re: [fatalnix] possible regex problem, not matching [In reply to] Can't Post

In this regexp:


Code
	if ($data =~ /^:(\w+)!\w+(\@|\-)[\w\.]+ PRIVMSG $irc_nick :(.*)/ ) {  
my ($nick, $chan, $msg) = ($1, $3, $4);


There is no capturing group $4. You have:

(\w+) = $1
(\@|\-) = $2
(.*) = $3

There is no fourth ($4) capturing group.
-------------------------------------------------


fatalnix
New User

Oct 19, 2008, 3:52 PM

Post #6 of 7 (5424 views)
Re: [KevinR] possible regex problem, not matching [In reply to] Can't Post

Oh yeah, sorry. So, is there any idea as to why these regex's aren't matching at all? the if statement appears to be coming false on the irb bot script, and I have taken the output from the socket on my terminal and put it in my regex testing script and the statement comes to be true..


KevinR
Veteran


Oct 19, 2008, 5:59 PM

Post #7 of 7 (5411 views)
Re: [fatalnix] possible regex problem, not matching [In reply to] Can't Post


In Reply To
Oh yeah, sorry. So, is there any idea as to why these regex's aren't matching at all? the if statement appears to be coming false on the irb bot script, and I have taken the output from the socket on my terminal and put it in my regex testing script and the statement comes to be true..


I don't know why that is. Maybe ask on www.perlmonks.com and see if anyone has a suggestion.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives