Filter with wildcards

Neville Smythe neville.smythe at optusnet.com.au
Wed Nov 1 19:24:53 EDT 2023


I agree David, regular expressions look intimidating at first sight. But in fact if you compare your intuitive attempt

filter tList with “*with [you,u] *”

with the regex which does what you set out to do

filter tList with regex “.*with (you|u) .*”

they are almost exactly the same – for very good reasons of course. The . is just the regex for a single character, the * says “any number incuding 0 of the preceding pattern”.

I don’t know your actual use-case, the above may be enough for all your searches, But I suspect you should allow for the required strings to be followed by punctuation or be at the end of the line, things which are hard to do with a simple LC wildcard search, at least in a single filter. 

The final tweak to account for a case insensitive search adds a flag at the front the of the regex (and I agree is rather arcane). If you want arcane, there is a possibly  better way to do the regex search for either the whole word “you" or the whole word “u”. You can use the code “\b” to indicate  a word boundary instead of a character, that is white space, punctuation or line start or end. 

filter tList with regex “.*with\b(you|u)\b.*”

As usual with a complex language there are alternative ways of accomplishing the same thing. Hmm, if to be truthful, my previous regex doesn’t do precisely the same thing as looking for word boundaries (hyphens, numbers, hard spaces…human language is so complicated).

I opine that regular expressions and sql are the two most useful technologies to add to the LC developer’s toolbox. After some basic user interface design principles course. Beyond those lie the web languages html, css, javascript (shudder). And then LCB, something I have yet to tackle.

BTW, apologies for the “numeric” when I meant “alphabetic” in the previous email. It seems I cannot write an email these days without at leat one mistke.

Neville

> On 1 Nov 2023, at 7:54 pm, David V Glasgow <dvglasgow at gmail.com> wrote:
> 
> This is the thing about regex, amazing,powerful, impressive, but scary as hell.
> 
> I will play with this a little, though… so thanks for your time when you should have been doing something else.  I appreciate it. 
> 
> Best Wishes,
> 
> David Glasgow
> Consultant Forensic & Clinical Psychologist
> Carlton Glasgow Partnership
> Director, Child & Family Training, York
> Honorary Professor (SOCAMRU), Nottingham Trent University
> 
> LinkedIn Profile
> 
>> On 31 Oct 2023, at 8:59 pm, Neville Smythe via use-livecode <use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com>> wrote:
>> 
>> Forgot any number of other chars after the non-numeric character
>> 
>> Filter tList with regex "(?i).*with (you|u)([^a-zA-Z].*|$)”
>> 
>> Now I’ve really got to go … hope I’ve got it all right this time! 
>> 
>> Neville Smythe






More information about the use-livecode mailing list