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

Gianluigi gradobag at gradobag.it
Tue Aug 22 09:24:39 CEST 2023


Il 22/08/23 09:14, Benoît Minisini ha scritto:
> Le 22/08/2023 à 00:34, T Lee Davidson a écrit :
>> On 8/21/23 11:16, Gianluigi wrote:
>>> I don't know what's behind the Python code, probably a loop since 
>>> that's what C seems to do.
>>
>> No, Python doesn't use a loop; it has a Findall function. It is quite 
>> simple and works as one would expect.
>>
>> [code]
>> import re
>>
>> f = open("file_with_ip_addresses.txt")
>> addresses = re.findall( "((?:[0-9]{1,3}\\.){3}[0-9]{1,3})", f.read() )
>> for ip in addresses:
>>      print(ip)
>> [/code]
>>
>>
>
> Maybe a similar method could be added to the RegExp class?
>
Hi Benoit,

if you can do it in Gambas it would be a great thing, but it's okay anyway.
So they have no more excuses :-)

Best regards

Gianluigi



More information about the User mailing list