Page 3 of 3

Re: Difficult find and replace problem (for me)

Posted: Wed Jun 24, 2020 6:45 pm
by richmond62
Unicode® Technical Standard #18
Unicode Regular Expressions

https://www.unicode.org/reports/tr18/tr18-21.html

Re: Difficult find and replace problem (for me)

Posted: Wed Jun 24, 2020 8:49 pm
by marksmithhfx
richmond62 wrote: Tue Jun 16, 2020 3:42 pm I couldn't understand any of your code, so I wrote my own. :?
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...

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
But as it turns out, this 1 line of LCscript including regex expression will do just as well:

Code: Select all

put replacetext(tline, "(\[[^\]]+])", empty) into tline

Re: Difficult find and replace problem (for me)

Posted: Wed Jun 24, 2020 8:51 pm
by richmond62
richmond62 wrote: ↑
Tue Jun 16, 2020 4:42 pm
I couldn't understand any of your code, so I wrote my own. :?
Err . . . actually . . . I lied. 8)

Re: Difficult find and replace problem (for me)

Posted: Sat Jun 27, 2020 1:30 pm
by marksmithhfx
richmond62 wrote: Wed Jun 24, 2020 8:51 pm
richmond62 wrote: ↑
Tue Jun 16, 2020 4:42 pm
I couldn't understand any of your code, so I wrote my own. :?
Err . . . actually . . . I lied. 8)
You're forgiven 8)

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) :lol:

Re: Difficult find and replace problem (for me)

Posted: Sat Jun 27, 2020 1:42 pm
by marksmithhfx
Thierry wrote: Wed Jun 24, 2020 5:46 pm
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.
Thanks, 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.

Mark

Re: Difficult find and replace problem (for me)

Posted: Sat Jun 27, 2020 3:10 pm
by Thierry
marksmithhfx wrote: Sat Jun 27, 2020 1:42 pm Thanks, 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.
You're welcome.
Actually, that's my primary documentation when in a need for some.
I'll have to go study that.. it's greek stuff (or maybe geek stuff)
Someone said that regex has a vertical learning curve.
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.

for Mark.jpg

And this one would be my way :roll:

for Mark 2.jpg

Best wishes,

Thierry

Re: Difficult find and replace problem (for me)

Posted: Mon Jun 29, 2020 12:17 pm
by marksmithhfx
Thierry wrote: Sat Jun 27, 2020 3:10 pm And last, as I did promess you,
here is one way to parse your Capital.txt entry.


for Mark.jpg


And this one would be my way :roll:


for Mark 2.jpg


Best wishes,

Thierry
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