Page 2 of 4

Re: matchtext and replacetext regex parts not working as expecte

Posted: Mon Mar 12, 2018 6:04 pm
by charms
They see this as feature, not as bug. So it might take some time until it gets tackled, unless there is somebody with a business license or somebody that needs this feature and pays to get it done? :mrgreen:

Re: matchtext and replacetext regex parts not working as expecte

Posted: Mon Mar 12, 2018 10:16 pm
by bogs
What part of it, exactly isn't working as expected?

Re: matchtext and replacetext regex parts not working as expecte

Posted: Tue Mar 20, 2018 6:45 pm
by charms
Does't return multiple regex matches. Only the first.

Re: matchtext and replacetext regex parts not working as expecte

Posted: Tue Mar 20, 2018 7:21 pm
by bogs
Which version of Lc/OS?

Re: matchtext and replacetext regex parts not working as expecte

Posted: Tue Mar 20, 2018 8:24 pm
by bogs
I take it you mean something other than this example.
Selection_003.png
MatchtextDemo.zip
(1.43 KiB) Downloaded 465 times

Re: matchtext and replacetext regex parts not working as expecte

Posted: Tue Mar 20, 2018 9:32 pm
by FourthWorld
I think the request is something I need as well: cases where the number of found elements is not knowable in advance.

Unless I missed something (and I would be delighted to find if I have), matchText currently requires us to pass in a variable for every instance we want, useful for many things but precluding cases where the number of instances isn't known.

Re: matchtext and replacetext regex parts not working as expecte

Posted: Tue Mar 20, 2018 10:01 pm
by bogs
Doesn't the demo I put there do that? I just ran the matchText through a repeat loop for each line, if you added 50 more lines of numbers and text, you'd find all the instances of numbers without knowing in advance what they are?

Or, like I said, maybe I am not understanding the question properly, it happens a lot :wink:

Re: matchtext and replacetext regex parts not working as expecte

Posted: Wed Mar 21, 2018 1:13 am
by FourthWorld
bogs wrote: Tue Mar 20, 2018 10:01 pm Doesn't the demo I put there do that?
I could not know that from the absence of posted code. So I downloaded it, unzipped it, launched LC, navigated to my Downloads folder, opened it, hunted around the UI for anything that looked like a button that might trigger the action being demonstrated, and when I didn't find one I hunted around in field scripts, then the card script, and finally the stack script where I found that it uses the same limited form of matchText being discussed here, but in a loop.

For the benefit of others interested in the meat of the demo:

Code: Select all

   put field "txtOne" into tmpText
   repeat for each line x in field "txtOne"
      get matchText(tmpText,"([0-9]+)-([0-9]+-[0-9]+)",areaCode,phone)
      put "(" & areaCode & ")" & phone & tab after field "txtResult"
   end repeat
True enough, many requests for engine features can be obtained by scripting. And since LC is a scripting language, perhaps it's not asking too much to try a little scripting now and then for things the engine doesn't provide one-liners for.

In my case I was looking for patterns which may span multiple lines, so line traversal wasn't an option. I suppose I could set the delimiter to some portion of the pattern I'm looking for, but for my purposes a simple pull-parser sufficed, at a fast enough clip that it does what I need.

I certainly didn't mind writing the parser. But when one does it often enough it becomes tempting to share the OP's dream of a built-in method. And with long blocks of text, it becomes helpful for the user waiting for the results as well.

Re: matchtext and replacetext regex parts not working as expecte

Posted: Wed Mar 21, 2018 2:18 am
by bwmilby
Yes, the OP essentially wants Thierry's match and replace integrated into LiveCode. From a backwards compatibility view, it is going to require new functions since instead of individual variables it will need to return arrays.

Re: matchtext and replacetext regex parts not working as expecte

Posted: Wed Mar 21, 2018 6:37 am
by FourthWorld
Yes, the array part is key for what the OP was asking for.

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.

Re: matchtext and replacetext regex parts not working as expecte

Posted: Wed Mar 21, 2018 2:00 pm
by bogs
Ah, so then I didn't understand the problem correctly, good to know. If your looking to just type one line instead of 3 or 4 (very short) lines, then yes, I don't know any way to do that and find every instance. I guess it does work as I expected it to, just not as the OP does. I don't see it working that way as a feature, just as how life is.

From what I thought he was asking, I thought it was more like the regexBuilder plugin in Lc, in particular this menu -
Selection_003.png
Selection_003.png (13.13 KiB) Viewed 14305 times
I haven't seen Thierry's match and replace yet, but I assume that, while I am sure it is brilliant, I am just as sure it is not one line long :wink:

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

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

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

Re: matchtext and replacetext regex parts not working as expecte

Posted: Wed Mar 21, 2018 4:03 pm
by jacque
I almost never download stacks here. If the script isn't posted I ignore the question. I am rarely at the computer when I read the forums, and I don't have time to mess with a download when I am because I'm usually working.

Re: matchtext and replacetext regex parts not working as expecte

Posted: Wed Mar 21, 2018 7:11 pm
by bwmilby
If you want to look at the source code, some files to start in are exec-strings.cpp, regex.cpp, and funcs.cpp; a few pertinent functions - MCR_exec, MCStringsEvalMatchText, MCStringsEvalMatchChunk, and MCStringsEvalReplaceText

The advantages to having it in the engine is that the field is only converted to unicode once, the regex is compiled once and reused (potentially cached otherwise), and there is no manual splitting of the array/maintaining position manually.

Re: matchtext and replacetext regex parts not working as expecte

Posted: Wed Mar 21, 2018 7:49 pm
by richmond62

Re: matchtext and replacetext regex parts not working as expecte

Posted: Wed Mar 21, 2018 8:02 pm
by richmond62
matchBox.png
Queer.