mIRC Home    About    Download    Register    News    Help

Print Thread
.pos property $regml() $regmlex() unicode #265044 20/02/19 08:27 PM
Joined: Jan 2004
Posts: 1,173
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,173
I'm helping rockcavera who first noticed parts of this.

The .pos property for $regml() and $regmlex() are not reporting the correct position when the string contains codepoints above 127.

Code:
//var %msg multibyte character $chr(233) test | echo -a pos: $pos(%msg,test) | noop $regex(%msg,/(test)/u) | echo -a regex: $regml(1).pos


In 7.52 and earlier

returns whether or not /u modifier is used:
pos: 23
regex: 23

In 7.53 and newer

returns whether or not /u modifier is used:
pos: 23
regex: 24

I then checked to see if $regmlex().pos did the same thing, and it does the same as $regml() in both versions. However at first I was having trouble avoiding an error message until discovering that $regmlex() wasn't working without using the <name> parameter even though /help indicates that [name] is optional.

Re: .pos property $regml() $regmlex() unicode [Re: maroon] #265057 22/02/19 11:37 AM
Joined: Dec 2002
Posts: 4,519
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,519
Thanks, this issue has been fixed for the next version.

Re: .pos property $regml() $regmlex() unicode [Re: Khaled] #265128 11/03/19 05:15 PM
Joined: Jan 2004
Posts: 1,173
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,173
Looks like the beta fixes the .pos issue in $regml and $remlex. Can you confirm if $regmlex is supposed to require the 'name' parameter instead of being optional as /help says? It's saying invalid parameter until I use the name:

Code:
//var %msg multibyte character $chr(233) test | echo -a pos: $pos(%msg,test) | noop $regex(%msg,/(test)/u) | echo -a regex: $regmlex(default,1).pos


Re: .pos property $regml() $regmlex() unicode [Re: maroon] #265131 11/03/19 06:16 PM
Joined: Dec 2002
Posts: 4,519
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,519
Yes, it needs it. $regmlex() has three parameters, two of which are optional, the first and the last. If you only use two parameters, it cannot know which two you've specified.

Re: .pos property $regml() $regmlex() unicode [Re: Khaled] #265133 11/03/19 06:49 PM
Joined: Jul 2006
Posts: 3,555
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,555
That's not correct.

Code:
//noop $regex(abcdefgh,/([a-h])([a-h])/g) | echo -a $regmlex(1,2) $regmlex(2,2)
$regmlex uses the first parameter as the Nth match, which is correct for regex-identifier behaviors. $regmlex is working correctly, it's the first parameter that is optional, the name; the others two are required, you want to access the Nth match and Mth capture for that match.

Edit: seems like the others two are not really required, not a huge fan of the design but if $regmlex(name,N) works, then $regmlex(N) should work the same when applicable

Last edited by Wims; 11/03/19 09:15 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: .pos property $regml() $regmlex() unicode [Re: Khaled] #265134 11/03/19 07:06 PM
Joined: Jan 2004
Posts: 1,173
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,173
But my example did use 2 parameters, and $regmlex did know which to use. If only 1 parameter is required, then why did $regmlex(1) fail while $regmlex(default,1) succeeded?

edit: in other words,

$regmlex(default,1).pos works,
$regmlex(default,1,1).pos works

but $regmlex(1).pos using the only parameter that's not optional is failing

Last edited by maroon; 11/03/19 07:19 PM.
Re: .pos property $regml() $regmlex() unicode [Re: maroon] #265141 12/03/19 09:48 AM
Joined: Dec 2002
Posts: 4,519
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,519
That is because the identifier is trying to guess which parameters you have specified based on their content. You should always specify the name.

Scripters have often requested that some identifier parameters be optional for the sake of convenience, ie. to decrease typing, make scripts shorter, etc. Unfortunately, the side-effect is that quite a few identifers that support optional parameters have to guess which parameter you've specified based on content. It also makes them more difficult to extend or update. It's not good design and if I could do it without breaking scripts, I would remove optional parameters in many identifiers.

Please note that I will not change how this feature works. It has worked like this for far too long and changing it now could easily break older scipts.