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

Benoît Minisini benoit.minisini at gambas-basic.org
Tue Aug 22 09:14:53 CEST 2023


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?

-- 
Benoît Minisini.



More information about the User mailing list