Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: regex not working..

by davido (Archbishop)
on May 12, 2012 at 15:41 UTC ( #970189=note: print w/ replies, xml ) Need Help??

in reply to regex not working..

The metacharacter "^" anchors your match to the left side of the string. The characters from your target string found at the left side of the string are "NOTICE", not "PASS". It's impossible for your target string to match [lefthand side of string]PASS.

Perhaps change it to:


That anchors to "/QUOTE PASS ", and then captures any non-space characters through the end of the string. If it's permissible to have space characters embedded within the field, change it to:


And if the field is optional:



Comment on Re: regex not working..
Select or Download Code
Replies are listed 'Best First'.
Re^2: regex not working..
by Anonymous Monk on May 12, 2012 at 16:55 UTC
    Thanks.. now just having the problem that it wont accept any of these:
    if (index($input, "/QUOTE") != -1) { my $str = $input; ($pass) = $str =~ m{/QUOTE\sPASS\s(.*?)$}; print $sock "/QUOTE PASS $pass\r\n"; print $sock "QUOTE PASS $pass\r\n"; print $sock "/QUOTE PASS$pass\r\n"; sleep 2; print $sock "QUOTE PASS $pass\r\n"; print "found quote $pass\r\n"; }
    as you can see im trying everything heh.. this is for my channel bot, currently i dont have X so im using it to op me and other operators and also to auto ban on certain words
      ... it wont accept any of these ...

      Not sure what you mean by 'it' (since you do not supply a self-contained, runnable code example) or 'these' (since you don't supply the data in your strings), but your code (as well as all the possibilities suggested by davido) seems to work for me.

      >perl -wMstrict -le "my $str = 'NOTICE AUTH :*** Bla bla must type /QUOTE PASS 16934'; my $pass; ($pass) = $str =~ m{/QUOTE\sPASS\s(.*?)$}; print qq{'$pass'}; " '16934'
        if i included the code the post would be massive. what im doing is connecting to an irc server.
        irc response while trying to connect: NOTICE AUTH :*** Ident broken or disabled, to continue to connect you +must type PASS 16934
        -code to answer the question.
        my $pass; while (my $input = <$sock>) { if (index($input, "/QUOTE") != -1) { my $str = $input; ($pass) = $str =~ m{/QUOTE\sPASS\s(.*?)$}; print $sock "QUOTE PASS $pass\r\n"; } }
        nothing happens..

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://970189]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2015-11-30 16:33 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (777 votes), past polls