Standard Library

JB sundown at pacifier.com
Tue Aug 12 17:26:00 EDT 2014


I see it is powerful and has a good value.  I  use it for some things
already but when it gets to more complex if then else replace code
it is still too complicated for me.

John Balgenorth


On Aug 12, 2014, at 10:11 AM, Peter Haworth <pete at lcsql.com> wrote:

> I've taken to using regex for input data validation, for example, email
> addresses, SSN, telephone numbers, URL,even stripping leading/trailing
> spaces.  There are various regex libraries online where people have
> contributed expressions for those purposes.
> 
> I just like the fact that one line of code is all it takes versus however
> many repeat loop lines it takes.  I've never checked out the relative speed
> of regex vs native LC script but for short amounts of data like that, it
> doesn't really matter.
> 
> Pete
> lcSQL Software <http://www.lcsql.com>
> Home of lcStackBrowser <http://www.lcsql.com/lcstackbrowser.html> and
> SQLiteAdmin <http://www.lcsql.com/sqliteadmin.html>
> 
> 
> On Mon, Aug 11, 2014 at 5:22 AM, Peter M. Brigham <pmbrig at gmail.com> wrote:
> 
>> I have very occasionally tried regex and can see that it is very powerful,
>> but to me it's also extremely opaque and I've never climbed far up the
>> rather steep learning curve. Partly this is because I've found that
>> essentially all of the stuff I would need regex for is do-able in native
>> LC, whose string manipulation capabilities are marvelous -- and much more
>> intuitive for me. Plus, LC is much faster than regex when chewing through
>> very large data sets, as long as you remember to "repeat for each…"
>> 
>> My two cents.
>> 
>> -- Peter
>> 
>> Peter M. Brigham
>> pmbrig at gmail.com
>> http://home.comcast.net/~pmbrig
>> 
>> Just wondering... when someone asks you, 'A penny for your thoughts'
>> and you put your two cents in, what happens to the other penny?
>> 
>> 
>> On Aug 9, 2014, at 11:29 PM, JB wrote:
>> 
>>> Thanks for the info about regex.  I bookmarked
>>> the website and will be using your advice.  I am
>>> pretty new to regex and even though I’ve spent
>>> a lot of time researching it you have helped me
>>> tremendously.
>>> 
>>> John Balgenorth
>>> 
>>> 
>>> On Aug 9, 2014, at 8:15 PM, Kay C Lan <lan.kc.macmail at gmail.com> wrote:
>>> 
>>>> On Sun, Aug 10, 2014 at 9:08 AM, JB <sundown at pacifier.com> wrote:
>>>>> One of the things I am interested in seeing more handlers
>>>>> and examples is regex.  It seems to be a very powerful
>>>>> tool with very few LiveCode examples.
>>>> 
>>>> The matchChunk and matchText functions are pretty straight forward to
>>>> use, it's building the regex that can be difficult if you don't live
>>>> with it regularly. If what you really need is examples of regex then I
>>>> highly recommend this online regex builder:
>>>> 
>>>> http://regex101.com/#pcre
>>>> 
>>>> The thing I like about it is that you can choose the 'Flavor' of regex
>>>> it uses, so unlike other online regex builders that use Javascript,
>>>> you can choose the same library that Livecode uses: PCRE. So if it
>>>> works on this site it should work in LC.
>>>> 
>>>> Even better, if you click on the Community tab at the top of the page
>>>> it will present you with a list of 100s and 100s of community provided
>>>> examples of regex, explains what they do, and it's as simple as copy
>>>> and paste into your matchChunk or matchText function to test in LC.
>>>> 
>>>> I will warn you though of one gotcha that is easy to trip on if you're
>>>> an occasional user of regex + LC. The standard matchText function
>>>> looks like this:
>>>> 
>>>> matchTex(yourDataVar,"regex(capturethis)expression",yourCapturedVar)
>>>> 
>>>> so any matches within () will be placed in your variable place holder.
>>>> 
>>>> In regex the | character is used as OR
>>>> 
>>>> so you might be looking for lowercase jpg file names, but you want
>>>> just the name, not the extension:
>>>> 
>>>> ([a-z]+)\.jpg  will work, but not if you also have some with a jpeg
>> extension.
>>>> 
>>>> ([a-z]+.jpeg will work for those, so these could be combined with the
>>>> | identifier:
>>>> 
>>>> ([a-z]+)\.jpg|([a-z]+)\.jpeg
>>>> 
>>>> Now I appreciate the regex experts will point out there is a much
>>>> better way to solve this problem than using |, but the point of this
>>>> is, if you use | in your regex, and place it in matchText or
>>>> matchChunk, you no longer have a single placeholder, so your matchText
>>>> function has to be amended accordingly:
>>>> 
>>>> 
>> matchText(yourDataVar,"([a-z]+)\.jpg|([a-z]+)\.jpeg",myJpgFile,myJpegFile)
>>>> 
>>>> It is easy, when copying regex off such sites listed above, or
>>>> building your own, and you know you are only finding x number of data
>>>> bites, to assume that that is how many capture variables you need, but
>>>> if OR is used, then you can easily end up needing double or triple the
>>>> number of variables.
>>>> 
>>>> Rule of thumb, always count the number of capturing () in the regex
>>>> and ensure you have the same number of allocated capturing variables.
>>>> 
>>>> HTH
>>>> 
>>>> _______________________________________________
>>>> 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
>>>> 
>>> 
>>> 
>>> _______________________________________________
>>> 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
>> 
>> 
>> _______________________________________________
>> 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
>> 
> _______________________________________________
> 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