[Gambas-user] I don't think regexp is working correctly, wrong number of fields are returned

Benoît Minisini benoit.minisini at gambas-basic.org
Mon Oct 9 10:37:12 CEST 2023


Le 09/10/2023 à 02:34, T Lee Davidson a écrit :
> On 10/8/23 19:56, Brian G wrote:
>> When Using regexp, the last field is never captured, unless I am just 
>> doing something wrong?
> 
> You are. ;-)  I can't count how many times I've done similarly.
> 
> Try this:
> [code]
> Sub printReg(MyReg As RegExp)
> 
>      Print "Count =";; MyReg.Count
>      For i As Integer = 0 To MyReg.Count ' Not Count - 1
>          Print "Field";; i;; "=";; Quote(MyReg[i].text)
>      Next
> 
> End
> [/code]
> 
> https://gambaswiki.org/wiki/comp/gb.pcre/regexp/_get :
> "The index of the first submatch is 1, and the index of the last one is 
> the Count property."
> 

Yeah, the interface of the RegExp class is silly, but I can't change it 
because of backward compatibility.

Usually I am happy with Gambas classes interface. But with that one I 
didn't initially designed, I was not careful enough. I take that as a 
lesson!

Regards,

-- 
Benoît Minisini.



More information about the User mailing list