Page 1 of 1

Filter with Regex

Posted: Mon Apr 03, 2017 4:13 pm
by Lagi Pittas
Hi

I have an ini file and wanted to make it easy to change the ON/OFF settings easily so I read it in and then
filter the lines to remove lines with comments emopty lines and non ON/OFF settings so that if the file is

Code: Select all

OPENONPAID=ON
CREDITCARD=ON
MIXDEFAULT=OFF
IMAGE=OPEN.png
SLIDESHOW=i1.png,o2.png
PRINTER=pOFFICE
I can filter to get

Code: Select all

OPENONPAID=ON
CREDITCARD=ON
MIXDEFAULT=OFF
Now I can get it to work outside of livecode using PRE regex using

Code: Select all

.*=(ON).*|(OFF).*
Im sure livecode doesn't allow the brackets so the closes i can get is

Code: Select all

 "*=O[NF]*"
This patches what I need but it also matches Printer=OFFICE so I have to put an extra letter in front of an "OFFICE" printer.


Is there a cheat sheet of what is acceptable in Livecode or at least how alternation works or will I have to find all Thierry's posts and save them for posterity (or is that Humanity)

Regards Lagi

Re: Filter with Regex

Posted: Mon Apr 03, 2017 5:14 pm
by Thierry
Hi Lagi,

You could try this one:

Code: Select all

   filter myIni with regex pattern "=(ON|OFF)$"
and if you would like to accept extra spaces or tabs in a line,
do that:

Code: Select all

   filter myIni with regex pattern "=\s*(ON|OFF)\s*$"
HTH

Re: Filter with Regex

Posted: Mon Apr 03, 2017 7:33 pm
by Lagi Pittas
Thanks Thierry

I thought the brackets weren't accepted in LC - maybe it was other stuff in my code ... , but this will help immensely for future regexes.

Thanks again

Your a star

Lagi