[Gambas-user] RegExp: How to find all matches of a pattern (global match)?

Gianluigi gradobag at gradobag.it
Tue Aug 22 14:10:30 CEST 2023


Il 22/08/23 13:36, Gianluigi ha scritto:
> Il 22/08/23 13:20, Benoît Minisini ha scritto:
>> Le 22/08/2023 à 00:29, T Lee Davidson a écrit :
>>> On 8/21/23 12:03, Jesus Guardon wrote:
>>>> The external parenthesis makes the group that captures all matches. 
>>>> Don't forget to apply the "/gmi" modifiers, which stands for 
>>>> "global", 
>>>> "multiline" and case "insensitive", if needed. See it working in my example:
>>>>
>>>> https://regex101.com/r/41vaTw/1
>>>
>>> Thank you for that pattern, Jesus. It is considerably shorter than 
>>> the one I was using. But, it still doesn't work in Gambas as there 
>>> is no Global Match compile option - at least not that I have found.
>>>
>>>
>>
>> Hi,
>>
>> The last commit 
>> https://gitlab.com/gambas/gambas/-/commit/61bab1771efd4778ae0bccacdbfdede03c7fdb14 
>> added a RegExp.FindAll() method.
>>
>> You are welcome to try it and tell me if it behaves as you expected.
>>
>> Thanks.
>>
> Hi Benoit,
>
> compiling i get this error :
>
> Making all in gb.pcre
> Making all in src
>   CC       gb_pcre_la-main.lo
>   CC       gb_pcre_la-regexp2.lo
> regexp2.c:323:10: fatal error: regexp_common.h: File o directory non 
> esistente
>   323 | #include "regexp_common.h"
>       |          ^~~~~~~~~~~~~~~~~
> compilation terminated.
> make[4]: *** [Makefile:514: gb_pcre_la-regexp2.lo] Errore 1
> make[3]: *** [Makefile:447: all-recursive] Errore 1
> make[2]: *** [Makefile:379: all] Errore 2
> make[1]: *** [Makefile:446: all-recursive] Errore 1
> make: *** [Makefile:387: all] Errore 2
>
> Regards
>
> Gianluigi
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----

Hi Benoit

the test here worked, but it's slower (5x) than the private function.
Am I doing something wrong?
[code]
Public Sub Main()

   Dim sText As String = File.Load("./Text1")
   ' Dim sExp As String = "(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})"
   Dim sExp As String = "((?:[0-9]{1,3}\\.){3}[0-9]{1,3})"
   ' Dim sExp As String = 
"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
   Dim s As String
   Dim aFind As String[]
   Dim hRegExp As New RegExp

   aFind = hRegExp.FindAll(sText, sexp, 524288, 4)

   For Each s In aFind
     Print s
   Next

End
[code]

Regards

Gianluigi



More information about the User mailing list