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

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Location: Singapore
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by charms » Mon Mar 12, 2018 6:04 pm

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:

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

Re: matchtext and replacetext regex parts not working as expecte

Post by bogs » Mon Mar 12, 2018 10:16 pm

What part of it, exactly isn't working as expected?
Image

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Location: Singapore
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by charms » Tue Mar 20, 2018 6:45 pm

Does't return multiple regex matches. Only the first.

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

Re: matchtext and replacetext regex parts not working as expecte

Post by bogs » Tue Mar 20, 2018 7:21 pm

Which version of Lc/OS?
Image

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

Re: matchtext and replacetext regex parts not working as expecte

Post by bogs » Tue Mar 20, 2018 8:24 pm

I take it you mean something other than this example.
Selection_003.png
MatchtextDemo.zip
(1.43 KiB) Downloaded 184 times
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by FourthWorld » Tue Mar 20, 2018 9:32 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: matchtext and replacetext regex parts not working as expecte

Post by bogs » Tue Mar 20, 2018 10:01 pm

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:
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by FourthWorld » Wed Mar 21, 2018 1:13 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by bwmilby » Wed Mar 21, 2018 2:18 am

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.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by FourthWorld » Wed Mar 21, 2018 6:37 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5435
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 2:00 pm

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 8181 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.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by jacque » Wed Mar 21, 2018 4:03 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: matchtext and replacetext regex parts not working as expecte

Post by bwmilby » Wed Mar 21, 2018 7:11 pm

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.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker


richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9358
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: matchtext and replacetext regex parts not working as expecte

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

matchBox.png
Queer.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”