Help with Regex (was Re: Switch, Case and wild-cards?)

Richmond richmondmathewson at gmail.com
Sun Dec 30 05:23:02 EST 2012


Those of you who don't want to feel faintly queasy had better tune out now.

Theoretical / Pedagogical rant follows.

----------------------------------------------------------------------------------------------------

Maybe I'm missing something (nothing particularly unusual there), but . . .

I don't really "get" REGEX.

And,frankly, why on earth would I, or anyone else for that matter, want 
to read through
some awfully long, wordy and obscure load of b*mf about it?

--------------------------

And the Wikipedia article:  http://en.wikipedia.org/wiki/Regex

starts off by describing the blindingly obvious, and then tries to dress 
the whole thing up in a load of jargon so
some fancy academic can draw a fat salary for understanding the 
blindingly obvious, and/or
being capable of thinking in a straight line . . . but, hey, that seems 
to be a universal problem.

--------------------------

What I do understand is that one needs a script(s) that looks for 
patterns in a string and replaces
them with other patterns, and that there needs to be a hierarchy of 
patterns.

Consider "my problem" (apart from all the other ones, that is):

I have a line of text in "some funny language" that goes like this;

1aQngh1swnpQavh

now there are the following considerations I have to deal with:

1. Every time I encounter a '1' it has to be shunted after the char it 
precedes.

2. Every time I encounter a 'Q' it has to be shunted before a char it 
comes after.

3. 1aQ (this is what is known as "the squirrel in the wood-pile" (and 
I'm sorry if I have offended any squirrels).

Now a hierarchy of pattern recognition means I have to trap '1aQ'
before I trap '1' and 'Q', because if I do things the other way round
everything is going to be "stewed squirrel" to coin a phrase.

Obviously there is the possibility that one might have to trap for 
'1*Q', where '*' may be anything, and that adds
a certain frisson to the whole thing.

Now, where I come from, that is not called REGEX, that is called either 
'logic' or 'getting things done in the right order'.

----------------------------------------------------------------------

So, I sat down at my kitchen table with a pile of chess pieces (I have 
about 5 identical sets lying around)
and lined them up in an order rather like '1aQngh1swnpQavh' and then, 
with some more as 'my second text field'
tried switching the things around - and after about 10 minutes 
everything made reasonably good sense.

And, as most programming seems to consist of getting things in the right 
order (or, as a friend of mine once remarked
"getting things in the right ordure") that is about all there is to things.

----------------------------------------------------------------------

Now you might be quite accurate in describing me as:

1. Child-like.

2. Not very good at abstract thought.

But when one considers that about 95% of people are pretty much like 
that, then
maybe chess pieces on the kitchen table, and/or plastic cups with beans, 
are not
a bad way to go.

--------------------------------------------------------------------

Richmond.




More information about the use-livecode mailing list