mIRC Home    About    Download    Register    News    Help

Print Thread
#272805 18/07/24 11:49 PM
Joined: Jul 2006
Posts: 4,187
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,187
Code
//echo -ag $regex(-sBnx,/^-|\G([snxmd])/Fg) -- first capture group $regml(1)

/F is documented as modifying $regml() results by including empty matches so that it works correctly, but with the above code, it fails and $regml(1) is set to 's' instead of $null.

First match is on '-', which has no capture group, this results in a non participating group being returned by pcre, which mIRC used to ignore without /F, but shouldn't be when /F is used.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #272806 19/07/24 07:02 AM
Joined: Dec 2002
Posts: 5,493
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,493
Thanks for your bug report. The regex tester here shows the same result as mIRC. Interestingly, other online regex testers show different results, and one regex tester reports \G as an invalid escape and refuses to parse the regex. If you change \G to G, $regml() reports 0 matches.

Joined: Jul 2006
Posts: 4,187
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,187
Quote
The regex tester here shows the same result as mIRC
your link shows a non participating capturing group for the first match, so no, it doesn't show the same result as mIRC.
\G is a perl, therefore PCRE construct and comes into play with the /g modifier, it's only valid for those two regex engines, which is why other engines will behave differently

Last edited by Wims; 19/07/24 01:31 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #272808 19/07/24 09:08 AM
Joined: Dec 2002
Posts: 5,493
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,493
Just to clarify: are you saying that the link I included is showing the result that you want to see in $regml()? Or are you expecting something different? So far, different regex testers have shown different results.

Can you describe exactly what you are expecting $regml() to return?

Looking through the code, and remember this is PCRE 8.45, the 's' is definitely being returned as a match. As far as I can see, there is no other way to interpret the PCRE 8.45 result after the regex call.

Last edited by Khaled; 19/07/24 11:24 AM.
Joined: Jul 2006
Posts: 4,187
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,187
Quote
Just to clarify: are you saying that the link I included is showing the result that you want to see in $regml()?
Yes. The website has an option to actually hide non participating group, sort of what you get without /F in mIRC (unsure it's exactly the same). When I open your link I see a non participating group for match 1.
Quote
the 's' is definitely being returned as a match
I didn't say otherwise, but 's' is match number two, not number one (and given the pattern having only one capturing group, there's a correspondance between match number and capture number), so $regml(1) should be $null and $regml(2) should be 's'


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2006
Posts: 4,187
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,187
I think I figured it out. I think it's related to how PCRE remove subsequent non participating group (again, non participating group and empty group are different things), which you mentioned here
However it seems that your implementation of this removal has a slight issue when the non participating group is the first group returned.

Because I can reproduce the problem without using \G with $regex(2,/([a-z])*2/F), which returns $regml(0) = 0 when it should be 1, and $regml(1) should be $null


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #272813 19/07/24 05:08 PM
Joined: Dec 2002
Posts: 5,493
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,493
Right, I think I see where the issue is in the regex code. I have made a change which returns the expected results for your regex examples. I have added these to my unit tests. This change will be in the next beta.

Joined: Jul 2006
Posts: 4,187
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,187
Great. In the second thread I linked to, we were two to mention that the help file was a bit wrong, looking at the help file now it's still the same, could you edit some phrasing?:
Quote
$regex([name], text, pattern)

[quote]You can assign a name to a $regex() call which you can use later in $regml() to retrieve the list of matches.
I have been suggesting a lot that mIRC's regex implementation doesn't offer us the actual matches (aka full matches), mIRC only offers captured groups, I would really love to see full match available, and it's only about returning the positions of the actual matches, which are returned by PCRE. In any case here it says that $regml retrieves the list of matches but it retrieves the list of captured groups, not matches.

Quote
$regml([name], N, [&binvar])

This returns the Nth match returned by a call to $regex(), $regsub(), or $regsubex().
Same as above, $regml returns captured groups, not matches

Quote
$regmlex([name], M, N, [&binvar])

If the /g modifier is used with a pattern, multiple results can be returned for that pattern. This identifier allows you to retrieve these results, where M is the Mth result and N is the () capture group number in that result. If N is not specified, it defaults to 1.
It is not necessary for /g to be used to have multiple captured groups, the beginning suggesting that $regmlex can only be used with /g which is not true. And "results" should really be renamed to "matches" (.match property is correctly saying 'match number' not 'results' or anything), M is the Mth match number.

Quote
F - make back-references refer to () capture groups, which is how standard regex works.
It should say something like "F - Include non-participating capturing groups in the list of captured groups, which mIRC ignores by default.
while

Quote
Note: If the F modifier is not used, \N references in patterns and N indexes in identifiers refer to the order in which matches are found, and $regml() will not include empty matches.
should really just be removed, because /F has nothing to do with \N reference in the pattern, and it's not about N indexes in identifier referring to the order of which matches are found, and empty groups (not matches) are different from non participating group.

By the way, I've said in previous thread that I wasn't sure if knowing if a group participated in the match was 'important' or not, but it is, because with /F now, empty captured and non participating groups are both returning $null, $regml().pos can be used to tell, returning 0 for non participating groups.








-


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard