mIRC Home    About    Download    Register    News    Help

Print Thread
#248513 10/10/14 05:13 PM
Joined: Oct 2014
Posts: 16
O
one4two Offline OP
Pikka bird
OP Offline
Pikka bird
O
Joined: Oct 2014
Posts: 16
Evening everyone smile

Here's what i have:

test.ini ; is the seperator

[Some/Stuff]
filters=^.*-2012.*$;^.*-2013-.*$

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

on text event:
%line = My.text.this.year-2013-test

Code:

  var %x = 1
  while ($gettok($readini(test.ini,%section,filters),%x,59)) {

    if ($regex(%line,/($v1)/si) == 1) {
      msg # $regml(1) 
}
 inc %x



For some reason this doesnt work frown
Id also wish to have the match in $regml(1) colored; like

My.text.this.year-2013-test

Any kind of help is appreciated smile Thanks!

Last edited by one4two; 10/10/14 05:23 PM.
Joined: Jul 2006
Posts: 4,150
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,150
That's because $v1 is not evaluated here.
Would you expect $v1 to be evaluated in $mid(/$v1/,1,1)? Because that's the exact same thing, you need to use $+ or similar to get it to be evaluated


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #248516 10/10/14 07:42 PM
Joined: Oct 2014
Posts: 16
O
one4two Offline OP
Pikka bird
OP Offline
Pikka bird
O
Joined: Oct 2014
Posts: 16
Hm.. i dont get smirk

if ($v1 iswm %line) {
do..
}

This is working. What do i have to do with $+ to make the regex thing work ?

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
It's an intricacy of the parser. An identifier can touch brackets in if statements or $identifiers() but not in the middle of a string.

Eg: Echo -a ($time) will show that as literal text.

You need to use $+ to have it evaluate and then concatenate the result to the rest of the string.

hixxy #248520 10/10/14 09:16 PM
Joined: Oct 2014
Posts: 16
O
one4two Offline OP
Pikka bird
OP Offline
Pikka bird
O
Joined: Oct 2014
Posts: 16
aaah smile now i got it!

And how would i challenge the 2nd part changing the color with the match text found in my .ini ?

Last edited by one4two; 10/10/14 09:26 PM.
Joined: Jul 2006
Posts: 4,150
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,150
Change the patterns so they have backreferences:

^(.*)(-2012)(.*)$;^(.*)(-2013-)(.*)$; etc

Now you can do:

Code:
var %x = 1
while ($gettok($readini(test.ini,%section,filters),%x,59)) {
  if ($regsubex(%line,/ $+ $v1 $+ /si,\1 $+ $chr(3) $+ 09 $+ \2 $+ \3) != %line) {
    msg # $v1
  }
  inc %x
}


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
alias test {
  var %i = 1, %line = My.text.this.year-2013-test, %section = test, %colour = 02, %filter
  writeini test.ini %section filters ^(.*-)(2012)(.*)$;^(.*-)(2013)(-.*)$
  while ($gettok($readini(test.ini,%section,filters),%i,59)) {
    %filter = $v1
    if ($regex(%line,/( $+ %filter $+ )/si) == 1) {
      echo -s msg # $regsubex(%line,/ $+ %filter $+ /,$+(\1,$chr(3),%colour,\2,$chr(3),\3))
    }
    inc %i
  }
}


This is my test alias, which made it work. Are you able to adapt that to suit your script or do you need my help doing that?

It's important to note that your filters need three sets of brackets in them now as shown here:

"^(.*-)(2012)(.*)$;^(.*-)(2013)(-.*)$"

The number that you want to colour needs to be within the second set of brackets.

Change the %colour variable to whatever colour you want the year to be.

hixxy #248541 11/10/14 06:47 AM
Joined: Oct 2014
Posts: 16
O
one4two Offline OP
Pikka bird
OP Offline
Pikka bird
O
Joined: Oct 2014
Posts: 16
nice smile but wouldnt that be easier using reaplace ?

like $replace($regml(1), $v1 ,$+(7,$v1,7) )

for some reason the color replacement is weired. shouldnt that work either ?

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
If you use $v1 there, that will be the result of $regex() so it will simply be '1' (if there's a match) or '0' (if there's no match).

You could use $replace rather than $regsubex but $replace will replace all instances of the matched text, rather than only one. If you're sure the matched text will only appear once in each line then you can use whichever one you prefer.

hixxy #248561 11/10/14 02:40 PM
Joined: Oct 2014
Posts: 16
O
one4two Offline OP
Pikka bird
OP Offline
Pikka bird
O
Joined: Oct 2014
Posts: 16
i see smile

and if i want

%line = My.text.this.year-2013-test

this -> ^.*\.text\.this\..*$

Ive tried with adding brackets but thats not working


Link Copied to Clipboard