Re: Can I replace text, depending on other text in the same line?
- View Source--- In email@example.com, "flo.gehrke" <flo.gehrke@...> wrote:
>Aaaaaaaaand I keep learning.
> --- In firstname.lastname@example.org, "mycroftj" <mycroftj@> wrote:
> > First, Thanks to Flo for the great answers and examples.
> > I learn more by studying them than anything else...
> > Question: Shouldn't (?=.+KLM) be (?=.*KLM) so KLM directly
> > after ABC is found?
> I didn't take into account that we could meet with a string 'ABCKLM'. Unfortunately, we were never informed of the list the member is trying to process. So we have to adjust the clip to specific needs, of course.
> > Next, I tried the clip even though it looked simple and I thought I
> > understood it but something strange happened and it seems like a bug
> > to me. Please check.
> No bug. 'DEFKLM' or 'KLMDEF' is matched only if, in this specific case, the 'T' option is set:
> ^!Replace "ABC" >> "DEF" HAST
> Cf. the Help on Clip Programming: "If the options T or C are not used, NoteTab will search for whole words if the search criteria does not contain spaces or other word delimiting characters. If the search criteria contains such delimiters, then NoteTab will accept matches that are not whole words."
> With RegEx, as in my proposal meant for the menu command, it's different because, normally, RegEx don't distinguish between substring and whole word unless you use word delimiters.
Thank you for the explanation. I've always had a bit of trouble with the way that was worded but think I get it now.
- View SourceThanks for the responses to my question on this. My first post - what a helpful lot you are!
Flo's search string ((ABC(?=.+KLM))|(KLM.*\KABC)) was great. It was easy to tailor it to the actual strings I was working with, it did just what I wanted and solved my problem. You would probably expect that, seeing how it had been tested by Flo, as documented in the message. I'll admit to knowing little about regular expressions, so I've got some work to do to understand why it works.
SNOBOL4 ... I've no experience with that, though I once enquired about a job using it. I think it was investigating natural language translation. But for this problem I was looking at coding something in a .NET language with its string handling. Fortunately, I've been saved from that.
--- In email@example.com, "flo.gehrke" <flo.gehrke@...> wrote:
> Search: (ABC(?=.+KLM))|(KLM.*\KABC)
> Replace with: DEFGH
> Regular Exp.: checked
> Tested against...
> ABC to DEFGH if line KLM.
> KLM to DEFGH if line ABC.
> ABC to DEFGH if ABC line KLM.
> ABC to DEFGH if line.
> ABC ABC to DEFGH if line KLM.
> DEFGH if ABC line KLM ABC.
> KLM ABC to DEFGH if line KLM.
> DEFGH if ABC line.
> This is not the Clip Group -- but, certainly, you are better off with a simple clip like this (discounting further details like 'case', 'whole word' etc)...
> ^!Jump Doc_Start
> ^!Find "^.*?KLM.*$" RS
> ^!IfError End
> ^!Replace "ABC" >> "DEFGH" HAS
> ^!Goto Skip_-3
> NT Pro 6.2 / NT Pro 7.0, Pre-release #8