mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2004
Posts: 2,127
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
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.

Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
Thanks, this issue has been fixed for the next version.

Joined: Jan 2004
Posts: 2,127
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
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


Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
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.

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2004
Posts: 2,127
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
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.
Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
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.


Link Copied to Clipboard