Macro: Using captured strings (from a replace) in subsequent code?

Randy Kramer rhkramer at gmail.com
Thu Dec 28 18:10:44 CET 2006


Question: 

Within a macro, is there a (direct/simple) way to use the results of capturing 
parenthesis (from a replace statement) in subsequent code?

I was hoping to do something like a = \1, b = \3, and c = \5; and then use 
those variables in the subsequent code.

Background: 

I'm using nedit version 5.5.

I'm writing a macro to change the format of my askRhk files.  I've written a 
(somewhat elaborate) replace statement that does part of what I need to do, 
and results in some useful content in \1, \3, and \5.

In subsequent code, I have to find the first of those that is non-blank and 
duplicate it in my file.  It would be ideal for me to be able to do something 
like assign those three captured strings to variables for use in the 
subsequent code (something like a = \1, b = \3, ...), but so far I haven't 
found a way.  Am I overlooking something?

Assuming there is not a way to use those captured strings in subsequent code, 
I'll find a workaround (like using find to select those (previously captured) 
strings (again) one at a time, then use a function like get_selection() to 
assign them to variables for subsequent processing. 


Randy Kramer

PS: Read further at your own risk ;-)

(There might be a possibility of doing something like what I want in the 
replace statement by adding something like a positive or negative lookahead, 
but the replace statement is already quite complicated, and I'm not 100% sure 
that would work.  Hmm, maybe I should paste the current replace statement 
here along with some sample data in case somebody sees something I'm 
overlooking--here is the search string used in the replace statement:

€‚ƒ\n-{3}\+{2} (.*)\s*(\n-{3}\+{2} (.*?)\s*\n){0,1}(-{3}\+{2} (.*?)\s*\n)
{0,1}

I haven't written the final version of the replace string yet, but you can get 
the gist of it by looking at the desired record prefix, a sample of which is 
below.

The current file consists of multiple records, each prefixed by something like 
this:

€‚ƒ
---++ [optional alternate "title"]
---++ [optional alternate "title"]
---++ Quotes

Some other records look like either of the following:

€‚ƒ
---++ Quotes

€‚ƒ
---++ Quotes
---++ Some other (valid) title

I want to convert those to a record separator/prefix to make the file look 
like a valid mbox file, including adding a few (useful to me) email headers, 
so after conversion, the record prefix looks something like this:

Desired record prefix:

<blank line>
From rhk Wed Dec 27 00:05:00 2006
Date: 27 Dec 2006 00:00:00 -0500
To: rhk
From: rhk
Subject: Quotes

T: <optional alternate "title">
T: <optional alternate "title">
T: Quotes

Some complicating factors:
   * (I wrote this before I created the alternate examples of the current 
record format--now it is pretty much redundant): I was not consistent with 
the titles (the things prefixed by ---++)--in some cases they appear as 
shown, sometimes there are two or three titles, usually with the "most 
significant" being at the bottom, and sometimes all instances of ---++ 
contain a "title" (there are no lines preceded by ---++ that are otherwise 
empty) meaning that there are only one or two instances of a line preceded by 
---++ (not three, with some blank).

Simplifying factors (hmm, this is probably redundant also, as I can control 
all of these things when I create the replace string or subsequent code):
   * I really don't care (too much ;-) which "title" is duplicated in the 
subject line.  (Ideally, it would be the most significant, but there is no 
way for code to determine for certain which that is, as I was not 
consistent.)
   * I really don't care whether I leave blank lines prefixed by "T: " or not.
   * If I leave the blank "T: " lines, I don't care whether they are before or 
after "T: " lines containing titles.



More information about the Discuss mailing list