Standard Library
JB
sundown at pacifier.com
Mon Aug 11 23:12:10 EDT 2014
I was interested in using a if then replace combination
but it seems it might be better done in LiveCode using
repeat for each. If the speed is not considerably faster
with regex it is not worth the trouble. The ability to read
my code like I am used to is more important than a small
increase in speed.
John Balgenorth
On Aug 11, 2014, at 8:03 PM, Alain Farmer <alain_farmer at yahoo.com> wrote:
> Regex is GREAT!
>
> I use it a LOT.
> Anyone need any help to grasp how it works ?
>
>
>
> On Monday, August 11, 2014 10:14:28 PM, JB <sundown at pacifier.com> wrote:
>
>
>
> That is nice to know!
>
> I was thinking I would speed up the
> longer text processing. You just did
> me a favor and save me a lot of time
> plus made it easier and faster by not
> using regex for text processing.
>
> I still appreciate the info others gave
> because I know I will use regex from
> time to time.
>
> John Balgenorth
>
>
> On 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
> _______________________________________________
> 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