mIRC Home    About    Download    Register    News    Help

Print Thread
Help detecting a cyan number and put it in a var? #261545 18/10/17 05:32 PM
Joined: Jul 2007
Posts: 40
B
beer Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2007
Posts: 40
Hi. I'm trying to figure out how I can detect a number that's cyan and stick that number in a variable. For example:

<echobot> Some text 17 25 19 more text.

In the above I want to find the cyan number (25) and store it in say `var %foundnum = `. First I tried to see if I could even find the cyan number but that failed using:

Code:
on ^*:text:*:#test{
  if ($regex($1-, $chr(3)[0-9]{2}$chr(32)[0-9]{2,})) { msg $chan found }
}


$chr(3) for the mirc color trigger, [0-9]{2} for "11" cyan color code, $chr(32) for a space, and [0-9]{2,} for a number thats at least two digits.

Any help is greatly appreciated!

Re: Help detecting a cyan number and put it in a var? [Re: beer] #261547 18/10/17 05:51 PM
Joined: Jan 2004
Posts: 1,181
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,181
This isn't fixing your problem entirely, but you're having the same problem as the previous thread, when you tried to put a comma in your regex search parameter. Also, your $chr(n) should not be touching anything because everything after the () gets ignored, as you can see from:

//echo -a $chr(46)test

$regex($1-, $chr(3)[0-9]{2}$chr(32)[0-9]{2,})

assuming there's a need to use $chr(32) instead of a literal space, it needs to change to

var %variable $chr(3) $+ [0-9]{2} $+ $chr(32) $+ [0-9]{2,})
$regex($1-, %variable)

This changes to result to being a 0 or 1 instead of displaying your $1- string, but it's not solving the problem of not matching your cyan color. I would think if you're wanting to match only cyan that your search should have $chr(3) $+ 11 in it somewhere.

Re: Help detecting a cyan number and put it in a var? [Re: maroon] #261548 18/10/17 07:09 PM
Joined: Jul 2007
Posts: 40
B
beer Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2007
Posts: 40
Ok, that worked. I also changed the first "[0-9]{2}" to simply "11" like you said. So now it detects the pattern correctly. I have a feeling that was the easy part though because I have no clue how I would copy that pattern into a variable, and then strip out the color coding, or cut/field separate it at the space. Or would you do an empty substitution for everything that is not the pattern? Or possibly substitute all of $1- with the pattern match somehow (regml?)?

It seems like this should at least echo the match but it doesn't:

Code:
on ^*:text:*:#test:{
  var %variable $chr(3) $+ 11 $+ $chr(32) $+ [0-9]{2,}
  ;  if ($regex($1-, %variable)) { msg $chan found match }
  if ($regex($1-, %variable)) { msg $chan matched $+ $regml(1) }
}


I also tried 2,3,4,5,6 for $regml(X) values to see if any part of the pattern got echoed but nothing did unfortunately.

Re: Help detecting a cyan number and put it in a var? [Re: beer] #261552 18/10/17 07:40 PM
Joined: Jan 2004
Posts: 1,181
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,181
I modified your code to have optional space-or-not between the number and the 11. Because your search string is simple, it can be done without regex, by finding the position of ^11 then adding 3. The text after the number can be stripped by using the undocumented behavior of several functions, including //echo -a $abs(123abc) returns 123

Code:
//var %text test $chr(3) $+ 11 987abc | var %variable $chr(3) $+ 11 $+ $chr(32) $+  ?[0-9]{2,} | echo -a $regex(%text,%variable) / $abs($mid(%text,$calc(3+$pos(%text,$chr(3) $+ 11,1))))


Re: Help detecting a cyan number and put it in a var? [Re: maroon] #261554 18/10/17 09:19 PM
Joined: Jul 2007
Posts: 40
B
beer Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2007
Posts: 40
It's almost there but I need to match the pattern exactly (due to badly formatted input - setting cyan, space, then setting another color):

$chr(3) $+ 11 $+ $chr(32) $+ [0-9]{2,}

or more loosely but would still work

$chr(3) $+ 11 $+ $chr(32) $+ `not $chr(3)`


I tried both of the following but it didn't match correctly:

$abs($mid($1-,$calc(3+$pos($1-,$chr(3) $+ 11 $+ $chr(32) $+ [0-9]{2,},1))))

var %variable $chr(3) $+ 11 $+ $chr(32) $+ ?[0-9]{2,}
$abs($mid($1-,$calc(3+$pos($1-,%variable,1))))

It doesn't seem to acknowledge the [0-9]{2,} part. It's weird that %variable works correctly with $regex but not with $pos...?

Re: Help detecting a cyan number and put it in a var? [Re: beer] #261555 18/10/17 09:29 PM
Joined: Jan 2004
Posts: 1,181
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,181
Because $pos does not habla regex. Also, the $abs trick only strips non alpha, so needs to add gettok like:

Code:
//tokenize 32 test $chr(3) $+ 11 987 654 | var %variable $chr(3) $+ 11 $+ $chr(32) $+  ?[0-9]{2,} | echo -a $regex($1-,%variable) / $gettok($mid($1-,$calc(3+$pos($1-,$chr(3) $+ 11,1))),1,32)


Re: Help detecting a cyan number and put it in a var? [Re: maroon] #261556 19/10/17 01:39 AM
Joined: Jul 2007
Posts: 40
B
beer Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2007
Posts: 40
Since $pos isn't regex-capable, then there's no way to use the [0-9]{2} in it, so wouldn't doing the $pos method essentially be a dead-end since I have to include it to find the correct match?

For example, regex correctly returns 1 match of %variable, but $gettok doesn't even return a position, though I'd expect it to incorrectly return 3 (test ^11 ^11) instead of 4 (test ^11 ^11 987):

Code:
//tokenize 32 test $chr(3) $+ 11 $+ $chr(32) $+ $chr(3) $+ 11 987 654 | var %variable $chr(3) $+ 11 $+ $chr(32) $+  ?[0-9]{2,} | echo -a $regex($1-,%variable) / $gettok($mid($1-,$calc(3+$pos($1-,$chr(3) $+ 11,1))),1,32)


This is why the pattern has to include [0-9]{2,} at the end.

Re: Help detecting a cyan number and put it in a var? [Re: beer] #261557 19/10/17 02:53 AM
Joined: Jan 2004
Posts: 1,181
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,181
The way you described it before, it was find "the cyan number". Now you're putting in a cyan followed by no number, then another cyan followed by the number. The problem isn't with gettok, it's with $pos, which was returning the 1st match because of "11,1" near the end. If you change that to 11,2 it will return the 2nd match and give you your number.

No matter how many matches I put in, I'm not able to get regex to say anything other than 1.

//echo -a $regex(test test test test,t)

Re: Help detecting a cyan number and put it in a var? [Re: maroon] #261558 19/10/17 03:53 AM
Joined: Jul 2007
Posts: 40
B
beer Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2007
Posts: 40
I noticed through trying to figure this out that sometimes the text is badly formatted, meaning sometimes cyan is followed by another color changed instead of a number. That's why the pattern has to match exactly (^11 [0-9]{2,}).

It sounds like we can't actually find the position because of this so is there another way to approach it? Is there any way to copy the matched regex pattern into a variable and then $abs the variable to get rid of the color coding?

Edit: I actually got it working using $regex, $regml, and your $pos method, so I think the problem is solved. Still need to do a little more testing to make sure though.

Thanks for the help maroon! Greatly appreciated!

Last edited by beer; 19/10/17 05:10 AM.
Re: Help detecting a cyan number and put it in a var? [Re: beer] #261560 19/10/17 04:55 AM
Joined: Jan 2004
Posts: 1,181
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,181
well, until you get regex working, you can find out how many cyan color tokens you have, then use a while() loop to see which are legit.

Code:
//tokenize 32 test $chr(3) $+ 12 $chr(3) $+ 11 $chr(3) $+ 14 14 $chr(3) $+ 11 234  test | var %i $wildtok($1-,11 *,0,3) | echo -a %i


Re: Help detecting a cyan number and put it in a var? [Re: maroon] #261561 19/10/17 05:13 AM
Joined: Jul 2007
Posts: 40
B
beer Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2007
Posts: 40
I think we just posted at the same time so I'm not sure if you saw the edit of my last post. If not, there's good news in it! smile