matchtext and replacetext regex parts not working as expecte
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: matchtext and replacetext regex parts not working as expecte
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?
Re: matchtext and replacetext regex parts not working as expecte
What part of it, exactly isn't working as expected?
Re: matchtext and replacetext regex parts not working as expecte
Does't return multiple regex matches. Only the first.
Re: matchtext and replacetext regex parts not working as expecte
Which version of Lc/OS?
Re: matchtext and replacetext regex parts not working as expecte
I take it you mean something other than this example.
-
- 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
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.
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: matchtext and replacetext regex parts not working as expecte
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
Or, like I said, maybe I am not understanding the question properly, it happens a lot
-
- 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
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
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: matchtext and replacetext regex parts not working as expecte
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
Script Tracker https://github.com/bwmilby/scriptTracker
-
- 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
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.
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: matchtext and replacetext regex parts not working as expecte
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 - 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
I guess I should have posted the code snippet, I forget not everyone wants to see how it is laid out, my apologies Richard
** 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.
From what I thought he was asking, I thought it was more like the regexBuilder plugin in Lc, in particular this menu - 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
I guess I should have posted the code snippet, I forget not everyone wants to see how it is laid out, my apologies Richard
** 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.
-
- 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
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
HyperActive Software | http://www.hyperactivesw.com
Re: matchtext and replacetext regex parts not working as expecte
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.
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
Script Tracker https://github.com/bwmilby/scriptTracker
-
- Livecode Opensource Backer
- Posts: 9358
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
-
- Livecode Opensource Backer
- Posts: 9358
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria