Filter Script & Patterns & Regex
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Filter Script & Patterns & Regex
I realize that this is a fairly intensive subject, but I think that an extensive Tutorial or example(s) for this subject is needed.
I am not the most sophisticated user, but I spent a whole day trying to understand and explore this subject of filters.
I have made some headway but I still feel far short from understanding what is needed for this capability. I have been told to use special repeat loops to achieve this capability, and I have, but it seems that a one line script that seems to have tremendous capability is the way to go.
There seems to be differences between using "FILTER" "with" and "Without", "patterns" and "patterns with Regex" and can be very daunting.
The Livecode Dictionary has some information but it is far shy of the abilities of this function.
I have been to the Regex site and that information, being very extensive, is as clear as mud, especially concerning Livecodes ability to utilize Regex.
I am not the most sophisticated user, but I spent a whole day trying to understand and explore this subject of filters.
I have made some headway but I still feel far short from understanding what is needed for this capability. I have been told to use special repeat loops to achieve this capability, and I have, but it seems that a one line script that seems to have tremendous capability is the way to go.
There seems to be differences between using "FILTER" "with" and "Without", "patterns" and "patterns with Regex" and can be very daunting.
The Livecode Dictionary has some information but it is far shy of the abilities of this function.
I have been to the Regex site and that information, being very extensive, is as clear as mud, especially concerning Livecodes ability to utilize Regex.
Last edited by chipsm on Mon Dec 11, 2017 5:36 pm, edited 1 time in total.
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Filter Script & Patterns & Regex
Regex is like dataGrids. I use them but do not understand them.
Craig Newman
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Re: Filter Script & Patterns & Regex
Just from my rudimentary understanding of this subject, this scripting can be very powerful if it is understood.
I too have somewhat avoided Datagrids for a similar reason.
I hope that the LiveCode team would be able to make this subject very clear. I know that someone there must have a clear understanding about this or it would not have been included as a function.
I too have somewhat avoided Datagrids for a similar reason.
I hope that the LiveCode team would be able to make this subject very clear. I know that someone there must have a clear understanding about this or it would not have been included as a function.
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
Re: Filter Script & Patterns & Regex
Yah, it can be confusing. I'm not sure I have it all straight, although I can manage fairly simple things ok.
My understanding (so far) is that -
. "filter with" = what you want to specifically see in the filtered result.
. "filter without" = what you want to specifically drop in the list.
. patterns = is a matter of matching whatever pattern you specify.
. regex = regular expressions.
Some examples of with and without (not using a repeat loop) -
Max's wiki has a pretty complete entry on it here, see if that helps. If your using loops, you might also check the entry for 'matchText' and 'matchChunk', since those target one line only at a time.
My understanding (so far) is that -
. "filter with" = what you want to specifically see in the filtered result.
. "filter without" = what you want to specifically drop in the list.
. patterns = is a matter of matching whatever pattern you specify.
. regex = regular expressions.
Some examples of with and without (not using a repeat loop) -
Code: Select all
put the folders into tmpFldrList
sort tmpFldrList ascending
// to get rid of hidden folders...
filter tmpFldrList without ".*"
Code: Select all
put the files into tmpFileList
sort tmpFileList ascending
// to get rid of hidden files...
filter tmpFileList without ".*"
// make sure only specific extensions show up, drop everything else...
filter tmpFileList with "*[.mc - .rev - .livecode]"
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Re: Filter Script & Patterns & Regex
I came upon this need because I needed to parse a tab delimited list of items.
I wanted to filter the list by checking on the 3rd tab item from my list.
I finally settled on this:
filter lines of (field) with "*" & tab &'*" & tab &"value*"
this will filter the list of lines based on the 3rd tabbed item for each line.
I wanted to filter the list by checking on the 3rd tab item from my list.
I finally settled on this:
filter lines of (field) with "*" & tab &'*" & tab &"value*"
this will filter the list of lines based on the 3rd tabbed item for each line.
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
Re: Filter Script & Patterns & Regex
Hint:
Don't forget that the asterisk * stands for ANY character, means also for a TAB,
so this will also filter lines based on the 4th, 5th etc. tabbed item, if any!
Re: Filter Script & Patterns & Regex
Here is another link from Max's wiki that may help cover regex better. Least I found it easier to understand.
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Re: Filter Script & Patterns & Regex
klaus,
can you please expand on your reply?
>Don't forget that the asterisk * stands for ANY character, means also for a TAB,
so this will also filter lines based on the 4th, 5th etc. tabbed item, if any!
are the tabs delimited "one for one" for each tab in the filter line?
ie. "*" & tab &"*" & tab - would by item 1 , and tab to the next item or 2 tabs items?
Sorry if I seem dense about this.
can you please expand on your reply?
>Don't forget that the asterisk * stands for ANY character, means also for a TAB,
so this will also filter lines based on the 4th, 5th etc. tabbed item, if any!
are the tabs delimited "one for one" for each tab in the filter line?
ie. "*" & tab &"*" & tab - would by item 1 , and tab to the next item or 2 tabs items?
Sorry if I seem dense about this.
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
Re: Filter Script & Patterns & Regex
Hi Clarence,
the asterisk is just a placeholder for one or MORE characters of ANY kind! So this:
...
filter lines of (field) with "*" & tab &'*" & tab &"value*"
...
Will also leave something like this in the field:
...
whatever TAB some string TAB another string TAB and yet another string TAB some numbers12245 TAB value
...
Best
Klaus
the asterisk is just a placeholder for one or MORE characters of ANY kind! So this:
...
filter lines of (field) with "*" & tab &'*" & tab &"value*"
...
Will also leave something like this in the field:
...
whatever TAB some string TAB another string TAB and yet another string TAB some numbers12245 TAB value
...
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Filter Script & Patterns & Regex
I was just trying to be cute with the "don't understand" thing.
That is not to say I understand.
But note that the filter command can be used without all that fancy regex/wildCard stuff. If you have a fid 1 with "a,b,c,d,e,f,g" and you:
you get the string without the "b".
One can move slowly from there, adding filter complexity piece by piece. Use the asterisk wildcard like Klaus mentioned, until you have enough confidence to try your first real regex gadget,
Then check out the "replaceText" function.
Craig
That is not to say I understand.
But note that the filter command can be used without all that fancy regex/wildCard stuff. If you have a fid 1 with "a,b,c,d,e,f,g" and you:
Code: Select all
on mouseUp
filter items of fld 1 without "b" into temp
answer temp
end mouseUp
One can move slowly from there, adding filter complexity piece by piece. Use the asterisk wildcard like Klaus mentioned, until you have enough confidence to try your first real regex gadget,
Then check out the "replaceText" function.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Re: Filter Script & Patterns & Regex
Craig,
I have been there. It gets more complicated as you add more. Especially when you use the Regex phrase - things get complicated. This where more information and help is needed by many developers including myself.
This is the cloudy part.
I have been there. It gets more complicated as you add more. Especially when you use the Regex phrase - things get complicated. This where more information and help is needed by many developers including myself.
This is the cloudy part.
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
Re: Filter Script & Patterns & Regex
Neither of the links I posted helped? The one about regex was particularly enlightening to me, and has all kinds of information about them.
Re: Filter Script & Patterns & Regex
chipsm wrote: ↑Mon Dec 11, 2017 6:00 pmI came upon this need because I needed to parse a tab delimited list of items.
I wanted to filter the list by checking on the 3rd tab item from my list.
I finally settled on this:
filter lines of (field) with "*" & tab &'*" & tab &"value*"
this will filter the list of lines based on the 3rd tabbed item for each line.
I'd use this:
########CODE to copy and paste#######
put the text of field test into myList
set itemdel to TAB
repeat for each line tLine in myList
if item 3 of tLine is "myValue" then
put tLine & return after newList
end if
end repeat
delete last char of newList
set the text of field test to newList
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-6#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Filter Script & Patterns & Regex
Clarence,
An alternative to FILTER for displaying only certain lines in a field is the HIDDEN property.
This is non-destructive. The original contents of the field are preserved.
You can restore the original display by:
Jim Lambert
An alternative to FILTER for displaying only certain lines in a field is the HIDDEN property.
Code: Select all
set itemdel to TAB
lock screen
repeat with x = 1 to the number of lines of fld "myFld"
if item 3 of line x of fld "myFld" is NOT "myValue" then
set the HIDDEN of line x of fld "myFld" to true
end if
end repeat
unlock screen
You can restore the original display by:
Code: Select all
lock screen
repeat with x = 1 to the number of lines of fld "myFld"
set the HIDDEN of line x of fld "myFld" to false
end repeat
unlock screen