use-livecode Digest, Vol 222, Issue 8

Andy Marshman andy at db-integration.co.uk
Mon Mar 7 11:52:43 EST 2022


Hi Mark,

In regex the full stop stands for any single character whereby the * means
any other characters. If you want to only find things that begin with a
character put a ^ infront of the character you are searching for. So ^a.
should only return apple in your example.


Regards

Andy

On Mon, 7 Mar 2022, 16:46 Mark Smith via use-livecode, <
use-livecode at lists.runrev.com> wrote:

> So, playing around a bit more I discovered “a.*” does not return words
> that “start with”, but rather words that “contain” the letter. So that
> explains “apple, banana”. What isn’t clear to me is I get the exact same
> result using “a.” with no asterisk, but if I search for “y.” it returns
> nothing rather than cherry. Consequentially I realize my confusion is due
> to a limitation of what these characters mean to regex. Can anyone clarify
> for me what the “.” and “*” are doing to change the filter?
>
> Thanks
>
> > On Mar 7, 2022, at 11:05 AM, Mark Smith <marksmithhfx at gmail.com> wrote:
> >
> > I am not an expert in regex or filtering by any means so Quentin’s
> message prompted me to take a closer look. I started with the dictionary
> entry for filter and I found this simple example:
> > filter items of "apple,banana,cherry" with regex pattern "b.*"
> >
> > Since we are not specifying a destination, the result is going into the
> “it" variable. I tried that and got the expected result “banana”. Next I
> tried “c.*” and got cherry and “d.*’ and got nothing. All good. Finally I
> tried “a.*” and got “apple, banana”. I was a bit surprised by that. Does
> anyone know why “a.*” breaks the pattern of returning a single item? Does
> it have something to do with the item being in the first position in the
> string?
> >
> > BTW, I did try putting the result into a variable and displaying that (…
> into temp; put temp) and got the same result.
> >
> > Also, I thought I might try a few experiments using “without regex
> pattern” and using “a.*” as the argument returned “cherry” so at least
> whatever it is doing it is consistent.
> >
> > Mark
> >
> >
> >> On Mar 7, 2022, at 8:58 AM, Quentin Long via use-livecode <
> use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com>>
> wrote:
> >>
> >> sez j. landman gay:
> >>> Interesting idea. There are 25 letters on each board, some are always
> repeats. I think I'd need
> >>> a good regex so I wouldn't have to run the filter command multiple
> times. How's your regex?
> >>
> >> I see you've already implemented something, but just for grins, here's
> my thought re: the One True Regex for this situation:
> >> AbsentChars is the name of a variable which contains all the letters
> that *aren't* on the board. My first attempt at the regex is…
> >> filter lines of WordList without "*[AbsentChars]*"
> >> However, that will remove all words that contain at least one letter in
> the specific character string "absentchars", which is not what I want. So,
> bring out the "do" keyword…
> >> do ("filter lines of WordList without" && quote & "*" & AbsentChars &
> "*" & quote)
> >>
> >> "Bewitched" + "Charlie's Angels" - Charlie = "At Arm's Length" Read the
> webcomic at [ http://www.atarmslength.net <http://www.atarmslength.net/>
> ]! If you like "At Arm's Length", support it at [
> http://www.patreon.com/DarkwingDude <http://www.patreon.com/DarkwingDude>
> ].
> >> _______________________________________________
> >> use-livecode mailing list
> >> use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com>
> >> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> >
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


More information about the use-livecode mailing list