Filter with Regex

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 366
Joined: Mon Jun 10, 2013 1:32 pm

Filter with Regex

Post by Lagi Pittas » Mon Apr 03, 2017 4:13 pm

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

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Filter with Regex

Post by Thierry » Mon Apr 03, 2017 5:14 pm

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 366
Joined: Mon Jun 10, 2013 1:32 pm

Re: Filter with Regex

Post by Lagi Pittas » Mon Apr 03, 2017 7:33 pm

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

Post Reply