Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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:

m{/QUOTE\sPASS\s(\S+)$}

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:

m{/QUOTE\sPASS\s(.+)$}

And if the field is optional:

m{/QUOTE\sPASS(?:\s(.+))?$}

Dave


Comment on Re: regex not working..
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2014-12-18 03:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls