Newbie Regex confusion

Stephen MacLean smaclean at madmansoft.com
Wed Aug 1 12:57:41 EDT 2018


Hi David,

While no expert on Regex, there are some online tools and libraries that you can use to work out the appropriate regex before putting it into your LC script.

Some sites I use:

https://www.regextester.com

https://regex101.com

https://www.rexegg.com/regex-quickstart.html

and 

http://www.regexlib.com

which has a lot of pre-built regex codes and examples. Most work without issue when putting them into LCS.

You can also take a look, if you haven’t already, at an example that I made using LCS and LCB, rsIsValid: https://forums.livecode.com/viewtopic.php?t=26653

HTH!

Steve MacLean

> On Aug 1, 2018, at 12:34 PM, David V Glasgow via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> 
> I am just dipping my toes in the shallows of regex, and have already stubbed my toe on a rock.  Well two, actually.
> 
> I am looking to identify the lines of a field (that contain lots of words and symbols with no particular structure or separator ) finding age related terms, which can be in a variety of forms.  I made a list of the terms that I want to use.
> 
> First problem:
> 
> I use the following filter line
> 
> filter lines of it with regex pattern i
> 
> … where i is a keyword lifted from my list.  Oddly, where i is just ordinary characters, it works fine.  However if it includes a wildcard symbol, it chokes with “execution error at line 9 (matchChunk: error in pattern expression), char 1”.  For example, if i = child* (intending to match child, childlike, childhood, childish etc).  I know that’s a bad example, because just ‘child' will do the trick.  However, there seems to be some voodoo needed to put a regex expression into a variable, is that right?
> 
> Second problem is the sheer brain ache from trying to work out how to efficiently  match lines containing 8 yo, 8 yr, 8yr, 8yo, 8 year and 8year, but not 18 year, 38yo etc etc.
> 
> The simplest way would be to include all variants in the keyword list.  However, that means more sweeps through the repeat loop.  And it wouldn’t solve the problem of excluding  18 yo, 28 yo matching, unless I can construct a regex expression which will test the absence of any number between 1 and 9 immediately before the actual string I am finding.  
> 
> Am I on a wild goose chase here?  
> 
> 
> 
> 
> Best Wishes,
> David Glasgow
> 
> 
> <http://www.i-psych.co.uk/> <https://twitter.com/iPsychApps>
> 
> <https://twitter.com/iPsychApps> <http://uk.linkedin.com/in/davidvglasgow>
> <http://uk.linkedin.com/in/davidvglasgow>
> _______________________________________________
> 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