matchtext and replacetext regex parts not working as expecte

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by FourthWorld » Wed Mar 21, 2018 8:08 pm

bogs wrote:
Wed Mar 21, 2018 2:00 pm
I guess I should have posted the code snippet, I forget not everyone wants to see how it is laid out, my apologies Richard :D
No need to apologize. It's cool that you devote so much time to helping people solve problems here. I was a bit grumpy yesterday, but like Jacque I do find it helpful when code is posted, ideally using the "code" tags provided here which aid readability and copying.

Code: Select all

** Future warning if I do post anymore stacks instead of code, for demos I generally skip putting buttons and other niceties in for one simple function, any code I do put in will (generally) be in the main stack, mouseUp in particular as a trigger since you can click anywhere out side of a field to trigger it.
That's helpful for people who have read this comment and remember it when downloading something you may post in the future. For dummies like me spelling out the trigger with something like a button labeled "Click Here!" helps. :)
***Edit - note to myself, not everyone uses the project or application browser, which shows you where the code is, stop assuming, which makes an a$$ out of 'u' and me.
It's a fair assumption, but this is one of the differences between UI and UX: the App Browser, Project Browser, and any number of other tools (Navigator, the MPath pane in devolution, etc.) provide good UIs show where code lies. But often code lies in multiple places, so it may not be obvious to the downloader that the relevant script happens to reside in one object or another.

I tend to look for code where I might place it, but not everyone thinks like I do so what seems obvious to me probably isn't obvious to others.

Especially helpful in tutorials is a button labeled "Script..." that opens the relevant script wherever it may be. But I realize there's a difference between making a complete tutorial designed to be used by thousands and a one-off to help a friend in the forums, so there's a case of diminishing returns at a certain level of completeness.

In short, please don't take my description of my laziness too seriously. Post whatever is most expedient for you to make. An imperfect solution that exists is infinitely more useful than a perfect one that doesn't.

That said, posting snippets of the relevant script tend to be read and replied to most frequently, so the "code" tags here offer a good option for simple algo. Of course scripts dependent on objects will probably benefit more from a complete example stack file, so I'm not sure there's a single "best" here. No worries. Continue to use your good judgment on a case-by-case basis.

As a side note, it occurs to me that it could be useful to resurrect and old REBOL View-inspired tool I was working on a while back to rapidly create objects specifically for demonstrating scripts. With it one could post a script with a modest easy-to-write header with a minimal description of objects and the tool would construct the stack from it on the fly. I stopped work on it because such scripts would be useless to anyone who didn't happen to have the tool, but maybe it might be fun for other purposes....
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by FourthWorld » Wed Mar 21, 2018 8:10 pm

richmond62 wrote:
Wed Mar 21, 2018 8:02 pm
matchBox.png

Queer.
1. MatchText is a function, but that statement attempts to use it as a command.

2. Any chance you might consider pasting scripts as text here using the "code" tags provided, rather than going to the extra effort of making screen shots? It would be more readable, and would encourage us to modify them into working forms, something I'm less inclined to do if I have to rewrite the entire thing from looking at a screen shot.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: matchtext and replacetext regex parts not working as expecte

Post by bogs » Wed Mar 21, 2018 8:37 pm

We're expecting an (unspecified accurately) amount of snow here in a bit, so I may or may not be pre-occupied for the next unspecified amount of time :shock: Nature is so much fun.

Your point earlier and all those made in the last post I find completely valid, for the dinky amount of lines, it should have just been posted as code. Sometimes my mind wanders, takes me with it, then leaves me on the side of the road dazed and confused is all :D

I never got too far into rebol, I dl'd the environment a few times, I even got it to run (although not in a conventional manner, big surprise eh?). I never got it to click with the way I think, so I must be missing beat or two on the old drum.

The tool you describe sounds like it would be an interesting experiment though :)
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: matchtext and replacetext regex parts not working as expecte

Post by richmond62 » Wed Mar 21, 2018 8:38 pm

burntFingers.png
burntFingers.png (12.61 KiB) Viewed 9443 times
No need to fuss about whether I post code or screenshots in this case 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: matchtext and replacetext regex parts not working as expecte

Post by richmond62 » Wed Mar 21, 2018 8:40 pm

for the dinky amount of lines, it should have just been posted as code
HOWEVER I wanted the slightly unhelpful error message to be there as well. 8)

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: matchtext and replacetext regex parts not working as expecte

Post by bogs » Wed Mar 21, 2018 8:43 pm

Oh Richmond, I knew *exactly* why you posted that snapshot the minute I looked at it.
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: matchtext and replacetext regex parts not working as expecte

Post by richmond62 » Wed Mar 21, 2018 9:05 pm

I knew *exactly*
LCarea.png
When have I EVER doubted you, "My Love" ?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by jacque » Wed Mar 21, 2018 10:13 pm

I was a bit grumpy yesterday
So was I, but I meant it. :)

It seems logical that if people want help from volunteers, they'd make it as easy as possible for the volunteer to do that. Posting images of scripts is about the same amount of work as a text copy/paste, with the limitation that the volunteer can't test it quickly. Stacks take too much time to deal with, I get paid to examine those. (And you never know what might be in a file uploaded to a public forum, even though our members are usually some of the nicest people.)

Most questions can be answered with a quick perusal of a script snippet. If the problem is due to the stack structure/message hierarchy then yes, you'd need to look at the stack. I have to say though, most of the time people do post actual scripts, and that's appreciated.

Special dispensation to Richmond to post silly images that make me smile.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: matchtext and replacetext regex parts not working as expecte

Post by SparkOut » Wed Mar 21, 2018 10:29 pm

jacque wrote:
Wed Mar 21, 2018 10:13 pm
Special dispensation to Richmond to post silly images that make me smile.
Especially if accompanied by a comment in the maither leid

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: matchtext and replacetext regex parts not working as expecte

Post by bogs » Wed Mar 21, 2018 10:44 pm

jacque wrote:
Wed Mar 21, 2018 10:13 pm
I was a bit grumpy yesterday
So was I, but I meant it. :)
Ha! Good luck trying to get me to believe THAT one :P
It seems logical that if people want help from volunteers, they'd make it as easy as possible for the volunteer to do that.
In this case, apparently the 'volunteer' made it more difficult :P

Posting images of scripts is about the same amount of work as a text copy/paste, with the limitation that the volunteer can't test it quickly.
I'll grant you that one, but since you gave dispensation to Richmond, I'll cash in on it myself and post as him from now on :P :P
Stacks take too much time to deal with, I get paid to examine those. (And you never know what might be in a file uploaded to a public forum, even though our members are usually some of the nicest people.)
I might finish erecting that shrine next to the Eiffel Tower someday, but the only payments I make are in humility and pain, not cash :P :P :P
( I promise, though, to not upload any deviant or malicious code to the forum :twisted: )
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by FourthWorld » Wed Mar 21, 2018 10:54 pm

FWIW error messages in the SE can be selected and copied.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by jacque » Wed Mar 21, 2018 11:32 pm

@bogs, my comments were generic, not at all aimed at you. You've actually provided a good many smiles here in the forums.

Richmond only gets special dispensation because I've known him a long time and I still remember he had holes in his kilt socks. I still wish he wouldn't post images of his scripts though. :P
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: matchtext and replacetext regex parts not working as expecte

Post by richmond62 » Thu Mar 22, 2018 11:39 am

@jacque

I have "gone up in the world" [well, probably if one wants to be accurate, "sideways"],
as some moths decided my kilt was rather a lovely bit of snack food about 4 years ago.

So am the proud owner of a relatively new kilt (the other one was 30 years old)
and 2 pairs of hole-free socks (although I'm sure we can find a work-around).

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by FourthWorld » Thu Mar 22, 2018 6:29 pm

FourthWorld wrote:
Wed Mar 21, 2018 6:37 am
In my case I only needed a list of offsets. I'll see if I can dig up the code I wrote for that. It's not fancy, using simple offset calls, but may be helpful for others with similar needs.
I found it. It's not fancy, and very specific to a problem I was working on, so it's likely of minimal value as-is. But still worth posting because it illustrates two things: offset is satisfyingly fast (no delimiter-tracking overhead); and offset has a handy optional third arg that can be used to specify where to begin the search, allowing forward traversal of strings within a loop without redundancy.*

The code below looks for tags within text where the pattern begins with "[WM-" and ends with "]", e.g.:
This is a test [WM-Test this is some stuff ] dgfdfg gdkhgkjhgkjhgkjh hgkjhgk ghkjhgk khg kgkjhg khg khg kh khg kjhg This is a test [WM-Test this is some more stuff ] dgfdfg gdkhgkjhgkjhgkjh hgkjhgk ghkjhgk khg kgkjhg khg khg kh khg kjhg
The goal is to return a list of offsets for those tags in the order in which they occur in the data. E.g., for the above it would return:
16,44
132,165
This function does that on larger samples that look like the snippet above at a rate of about 36 MB/second:

Code: Select all

on mouseUp
      put GetTags("[WM-","]", s ) into fld "list"
end mouseUp

function GetTags pStartTag, pEndTag, pSrc
   put empty into tFoundOffsets
   put 0 into tPtr
   repeat len(pSrc)
      put offset(pStartTag, pSrc, tPtr) into tStartPos
      if tStartPos = 0 then exit repeat
      add tPtr to tStartPos
      put offset(pEndTag, pSrc, tStartPos) into tEndPos
      if tEndPos  = 0 then exit repeat
      add tStartPos to tEndPos
      put tStartPos,tEndPos &cr after tFoundOffsets
      put tEndPos into tPtr
   end repeat
   delete last char of tFoundOffsets -- trailing cr
   return tFoundOffsets
end GetTags
* Historical trivia: IIRC the optional third argument to the offset function (also added to lineoffset and itemoffset) was introduced to the xTalk family of languages by Gary Poppitz while he was Principal Architect of the SuperCard team, for SuperCard 1.5 (or 2.0?) back in the early '90s.

Non-obvious at first, the benefits prove tremendous: without it, to get the same results we had to make a copy of the source string, deleting chunks after each find as we go, resulting in a lot of dynamic memory shuffling as the source string is first copied and then gets truncated each time through the loop. With this start position arg we get to work with just one string, which remains unchanged in place as we walk through it.

A C and Assembly expert who spent little time in scripting languages himself, Gary also introduced the explicitVariables global property and other additions useful for professional work.

Sadly, I learned last year that Gary passed away in 2012, one week shy of his 59th birthday. Though he spent most of his career in systems programming and device drivers, his contribution to the xTalk family of languages is the legacy I admire him the most for, along with his quick, dry wit.

A toast to Mr. Poppitz! May he streamline the work in Heaven as well as he did our work here on Earth.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bwmilby
Posts: 462
Joined: Wed Jun 07, 2017 5:37 am
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by bwmilby » Thu Mar 22, 2018 6:50 pm

Your code is very similar to the ReplaceText code. It does a similar thing working through the chunk. That’s why I think implementing in the engine wouldn’t be that monumental of an effort. I think we just need to define the LCS syntax first. I’m also wondering if I could do it in LCB (access to composite types being the question).

Post Reply