It sets a variable(%findvar%) to the regex find expression because it
is used more than once(eliminates typos).

Starts a loop that finds the first comment with a line added
underneath. The regex(%fundvar%) looks for multiple lines between
comments, which causes those that don't have any added lines to be
skipped.

The Find CRS1 selects the text inside the comment and this is set to
the variable %cc%

Jumps to the start of the line.

Finds the regex expression %findvar% again, but this time selects the
entire regex and not just the text in the comment. First search used
CRS1 and second search uses CRS.

Then replace the <li><b> part of the entry with <li>%cc%<b>, which
add the region to the entry.

Jump line end deselects the selection, places the cursor above the
next comment and restarts the loop.

The interesting part of this little clip is that a post here that
showed me how to use FIND, a couple of other posts on arrays and a
little serendipity allowed me to code a clip that is almost
instantaneous (except in Vista).

I have been working on this for about two years and every solution I
came up with was not satisfactory. This one works so well that I felt
obligated to post it.

>
> I've been working on a problem for a while and came up with a
> solution that I would like to share(...)Then replace the <li><b>
> part of the entry with <li>%cc%<b>, which add the region to
> the entry.

Paul,

I understand that the lines...

<!-- Mexico: -->
<li><b><i>Melbourne...

are replaced with...

<!-- Mexico: -->
<li>Mexico: <b><i>Melbourne...

Isn't that done with just the following line...

^!Replace "(\w+:\x20)\K(-->\r\n<li>)(<b><i>)" >> "$2$1$3" AWRS

...matching all occurrences of that pattern?

Regards,
Flo

paulmaser

Flo; You are certainly a master at this. I will have to spend some time trying to figure out what you are doing. Thanks, as always. Paul

Message 3 of 15
, Mar 2 10:05 AM

0 Attachment

Flo;
You are certainly a master at this.
I will have to spend some time trying to figure out what you are doing.
Thanks, as always.
Paul

... Flo; Thanks again, I ve had some time to play with, but if there are multiple lines entered after the comment it ignores them. This was always my problem.

Message 4 of 15
, Mar 2 6:48 PM

0 Attachment

> ^!Replace "(\w+:\x20)\K(-->\r\n<li>)(<b><i>)" >> "$2$1$3" AWRS

Flo;
Thanks again, I've had some time to play with, but if there are
multiple lines entered after the comment it ignores them. This was
always my problem. Is there some magic formula in regex to get this to
handle multiple entries/

Paul

Flo

... Paul, So far, I understood that there are comments like... and added lines like... Melbourne Age asdf mjmdof aselkmd

Different from your first example, the number of those "added lines" now differs from comment to comment. I assume that the "added lines" contain *no CRNL* (i.e., they are multiple lines of a single paragraph only).

Flo; Once again, your regex is beyond my ability to comprehend and I will have to dive into the manual to understand what you are doing. It looks like it gives

Message 8 of 15
, Mar 4 8:19 AM

0 Attachment

Flo;
Once again, your regex is beyond my ability to comprehend and I will have to dive into the manual to understand what you are doing. It looks like it gives me exactly what I needed. Using the clipboard to store is pretty nifty. Your use of \K is really inovative.
Thanks again;
Paul

Um yes Flo, can you break that down for the slow kids in the back here?

Message 9 of 15
, Mar 4 1:52 PM

0 Attachment

Um yes Flo, can you break that down for the slow kids in the back here?

paulmaser wrote:

> Flo;
> Once again, your regex is beyond my ability to comprehend and I will have to dive into the manual to understand what you are doing. It looks like it gives me exactly what I needed. Using the clipboard to store is pretty nifty. Your use of \K is really inovative.
> Thanks again;
> Paul
>
>> When running the following clip on these lines...
>>
>>
>> ^!SetScreenUpdate Off
>> ^!SetWordWrap Off
>> ^!Jump Doc_Start
>> :Start
>> ^!Find "(?s)^<!--[^-]+-->\x20\r\n<li>.+?((?=^<!)|\Z)" RS
>> ^!IfError End
>> ; Long line start
>> ^!SetClipboard ^$GetDocMatchAll("^<\!--\x20\K([^-]+)(?=-->\x20\r\n<li>)")$
>> ; Long line end
>> ^!Replace "(<li>)(<b>)" >> "$1^$GetClipboard$$2" HARS
>> ^!Jump Select_End
>> ^!If ^$GetRow$=^$GetTextLineCount$ End
>> ^!Goto Start
>

>
> Um yes Flo, can you break that down for the slow kids in the
> back here?

Here we go...

(?s) = "dot matches all" modifier (also NL to match multiple lines)

^<!-- = matches at start of a comment line

[^-]+ = character class: any character that is no "-" (i.e. the body of comment)

-->\x20\r\n = matches at end of comment line, followed by a space (in hex), and a CRNL

<li> = matches at start of an added line (to identify added lines following a comment line)

.+?((?=^<!)|\Z) = matches one or more (non-greedy) following added lines up to the next comment line using a Positive Lookahead Assertion (?=^<!) embedded in an alternation: matches either before "^<!", i.e. the start of a comment line, or at end of list (\Z) if last line is an added line.

The second RegEx (in ^$GetDocMatchAll$)...

^<\!--\x20\K([^-]+)(?=-->\x20\r\n<li>)

matches the body of a comment line only:

^<\!--\x20\K = matches at start of comment line (obviously the escaping of the exclamation mark isn't necessary here), followed by a space (in hex) but, with \K, doesn't select the match. Since ^$GetDocMatchAll$ searches only within the selection made by ^!Find, it captures the body in that block only (cf the "CRS1" used by Paul to capture the first subpattern only).

I love to play with that different solutions. I also like Pauls approach. Maybe it's a little bit slower with very large lists because every ^!Find and ^!Jump slows down a clip whereas those ^$GetDoc-Functions are extremely fast.

But in the end it doesn't matter very much -- "many roads lead to Rome" ;-)

Please note when testing it with Paul's big list: This list is processed, i.e. it contains those bodies already; also, you have to remove a dozen CRNL inserted by this forum. That is, all lines have to start either with "<!--" or "<li><b>" (when word wrap is off).

paulmaser

Flo; I am having a hard time understanding how Z works. Could you expand on your explanation? Thanks; Paul

Message 11 of 15
, Mar 5 2:41 PM

0 Attachment

Flo;
I am having a hard time understanding how \Z works.
Could you expand on your explanation?
Thanks;
Paul

Flo

... Paul, There s an upper Z and a lower z. Imagine a document that ends with the following two lines... This is next to last line This is the last line With

>
> Flo;
> I am having a hard time understanding how \Z works.
> Could you expand on your explanation?

Paul,

There's an upper \Z and a lower \z. Imagine a document that ends with the following two lines...

This is next to last line
This is the last line

With lower \z...

^!Find "line\z" RS

...the RegEx will match the word "line" at the end of the last line in case it isn't followed by another NL.

With upper \Z, the RegEx will match that word, no matter if there is one more NL or not.

Regards,
Flo

paulmaser

Flo; Thanks, that helps. By the way, that is a nice piece of work you coded. You showed me some stuff I would have never figured out. Paul

Message 13 of 15
, Mar 6 12:31 PM

0 Attachment

Flo;
Thanks, that helps.
By the way, that is a nice piece of work you coded.
You showed me some stuff I would have never figured out.
Paul

>
> There's an upper \Z and a lower \z. Imagine a document that ends with the following two lines...
>
> This is next to last line
> This is the last line
>
> With lower \z...
>
> ^!Find "line\z" RS
>
> ...the RegEx will match the word "line" at the end of the last line in case it isn't followed by another NL.
>
> With upper \Z, the RegEx will match that word, no matter if there is one more NL or not.
>
> Regards,
> Flo
>
>

Michael Frascinella

Flo, I tried a test of ^!Find line z RS and ^!Find line Z RS using your sample text. Both assertions found only the last instance of line on the last

Message 14 of 15
, Mar 6 4:41 PM

0 Attachment

Flo,

I tried a test of
^!Find "line\z" RS
and
^!Find "line\Z" RS
using your sample text.

Both assertions found only the last instance of "line" on the last line
and not on a preceding line. Your explanation and the online help said
they work slightly differently but I don't see it.