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

Robert Sneidar slylabs13 at me.com
Sun Dec 30 15:08:02 EST 2012


I ran into a similar problem doing search and replace in word to clean up text from some data system destined for excel. My solution was often to replace a character or string I wanted to preserve with a placeholder, replace or remove what remains, then restore my placeholders with the original values. In situations like this, work with bigger strings first, and sometimes you need to work it end to beginning, especially if you are using a word or character counter to keep track of where you are. 

Bob Sneidar
IT Manager
Calvary Chapel CM
Sent from iPhone

On Dec 30, 2012, at 2:23, Richmond <richmondmathewson at gmail.com> wrote:

> 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.
> 
> _______________________________________________
> 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