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

Jesus Guardon ea7dfh at ea7dfh.com
Mon Aug 21 18:03:09 CEST 2023

El 21/8/23 a las 15:28, T Lee Davidson escribió:

> That is, in fact, what I have done as I couldn't get RegExp to do what I 
> wanted and didn't want to switch to Python.
> I was hoping to be able to do a RegExp global match on the entire text 
> without having to parse it line by line.
Hi, Lee

This is what I have came up with using a similar approach, but as a raw 
regexp. You must adapt and escape to gambas language.


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:


All matches should be accessible as an array, if I am not mistaken.

Please, test it and report back if it worked for you.

On the other hand, there are other ways to write the regexp to be more 
accurate and look for an actual (valid) IPv4, for example:


But I don't think it's worth it for your needs.

More information about the User mailing list