Difficult find and replace problem (for me)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Difficult find and replace problem (for me)
Unicode® Technical Standard #18
Unicode Regular Expressions
https://www.unicode.org/reports/tr18/tr18-21.html
Unicode Regular Expressions
https://www.unicode.org/reports/tr18/tr18-21.html
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Difficult find and replace problem (for me)
Hi Richmond, the basic premise was I wanted to take a string like this: FirstPart[19]SecondPart and turn it into just FirstPartSecondPart, dropping the bit in brackets. When I want to do something like that I generally don't concern myself with whether the [text] is in the beginning, middle or end and just write code to handle it anywhere. So...richmond62 wrote: ↑Tue Jun 16, 2020 3:42 pmI couldn't understand any of your code, so I wrote my own.
Code: Select all
put offset ("[", tline) into tStart -- see if we have a [
if tStart > 0 then -- yup, so find the closing match
put offset ("]", tline) into tEnd -- got it
if tEnd > tStart then -- if the end is greater than the start ie. [ ]
put char 1 to tStart-1 of tline into tFirst -- put the preceeding bit into First
put char tEnd + 1 to the number of chars of tline of tline into tLast -- put the succeeding bit into Last
put tFirst & tLast into tline -- put First and Last together, all done
end if
end if
Code: Select all
put replacetext(tline, "(\[[^\]]+])", empty) into tline
Last edited by marksmithhfx on Wed Jun 24, 2020 8:54 pm, edited 1 time in total.
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Difficult find and replace problem (for me)
Err . . . actually . . . I lied.richmond62 wrote: ↑
Tue Jun 16, 2020 4:42 pm
I couldn't understand any of your code, so I wrote my own.
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Difficult find and replace problem (for me)
You're forgivenrichmond62 wrote: ↑Wed Jun 24, 2020 8:51 pmErr . . . actually . . . I lied.richmond62 wrote: ↑
Tue Jun 16, 2020 4:42 pm
I couldn't understand any of your code, so I wrote my own.
Did you see my post edit added after you replied? I added the regex example to have them both in the same place. Also Thierry responded somewhere back a ways in this thread. I'll have to go study that.. it's greek stuff (or maybe geek stuff)
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Difficult find and replace problem (for me)
Thierry wrote: ↑Wed Jun 24, 2020 5:46 pmThanks, helps (me) if I am working through a specific problem or solution, so this is great. Also, many thanks for the link to the RegexBuddy page. It looks like a great intro.2. find the literal "[" followed by any number of characters but NOT "]" and lastly "]"
the escaped \[ is mandatory because [ is a meta-character for regex.
the carret inside [ ] means NOT.
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: Difficult find and replace problem (for me)
You're welcome.marksmithhfx wrote: ↑Sat Jun 27, 2020 1:42 pmThanks, helps (me) if I am working through a specific problem or solution, so this is great.
Also, many thanks for the link to the RegexBuddy page. It looks like a great intro.
Actually, that's my primary documentation when in a need for some.
Someone said that regex has a vertical learning curve.I'll have to go study that.. it's greek stuff (or maybe geek stuff)
I'm not so sure, it's so vertical, but yes, it certainly takes time to get into it.
Of course, I'm not talking of copy-paste a regex from the Net
and then crying in a forum for help
If you accept an analogy, one can't play Chess until he knows the rules,
and knowing the rules is not enough to be a good Chess player.
And last, as I did promess you,
here is one way to parse your Capital.txt entry.
And this one would be my way
Best wishes,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Difficult find and replace problem (for me)
Wonderful, thank you so much for providing those. I will have to take some time to deconstruct what you are doing and compare it to my own. Interesting how many different ways there are to accomplish the same thing in programming.
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS