#261545 - 18/10/17 06:32 PM
Help detecting a cyan number and put it in a var?
|
Ameglian cow
Registered: 21/07/07
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: 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!
|
Top
|
|
|
|
#261547 - 18/10/17 06:51 PM
Re: Help detecting a cyan number and put it in a var?
[Re: beer]
|
Hoopy frood
Registered: 12/01/04
Posts: 1057
|
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.
|
Top
|
|
|
|
#261548 - 18/10/17 08:09 PM
Re: Help detecting a cyan number and put it in a var?
[Re: maroon]
|
Ameglian cow
Registered: 21/07/07
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: 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.
|
Top
|
|
|
|
#261554 - 18/10/17 10:19 PM
Re: Help detecting a cyan number and put it in a var?
[Re: maroon]
|
Ameglian cow
Registered: 21/07/07
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...?
|
Top
|
|
|
|
#261556 - 19/10/17 02:39 AM
Re: Help detecting a cyan number and put it in a var?
[Re: maroon]
|
Ameglian cow
Registered: 21/07/07
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): //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.
|
Top
|
|
|
|
#261558 - 19/10/17 04:53 AM
Re: Help detecting a cyan number and put it in a var?
[Re: maroon]
|
Ameglian cow
Registered: 21/07/07
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!
Edited by beer (19/10/17 06:10 AM)
|
Top
|
|
|
|
|
|