Named Capture - using find and inserting


Don - htmlfixit.com
 

I have a find that say looks for this:

^(?<FirstName>[^\t]*)\t(?<LastName>[^\t]*)\t


Basically finds two columns of data separated by a tab (with a following tab).


So I should be able to then insert that in something like:

^!InsertText Dear $<FirstName>,


But it doesn't work.




Don - htmlfixit.com
 

So, if I work on this line:
One[tab]Two[tab]Three[tab]Four[tab]Five[tab]

With this line of code:
^!Replace "(?<One>[^\t]*)\t(?<Two>[^\t]*)\t(?<Three>[^\t]*)\t.*" >> "$<Three>\t$<Two>\t$<One>\t" RAWS

I get:
Three[tab]Two[tab]One[tab]

So that works.


But with this:
^!InsertText One: $<One>

Just inserts the literal ... $<One>, as opposed to the value, so I guess I can't use this named capture group in an inserttext as it is not really a variable per se?

I realize I can use ^$GetReSubStrings$ and assign the finds to an array, but then I have to refer to them by number which seems a bit harder to follow and get correct.






joy8388608
 

It doesn't appear you received a useful answer yet so I'll try to guess what you are trying to do and point you in what may be the correct direction.

It seems you want to extract Firstname and Lastname (each field always followed by a TAB) from one or more lines. I don't think your approach will work but you may get an idea this way.  Place these three lines of data in a document as lines 1-3. Fields are separated by tabs.

Run the clip which places the cursor at the first line and finds the first field (Firstname) and second field (Lastname).

The GetReSubStrings line copies found groups 1 and 2 into an array which you can use directly or, as I did, first copy them to individual variables.

If you want to do this for multiple lines, you will have to write the code to loop, add error testing, etc. but I didn't want to get ahead of myself.

Hope this helps.

Joy


Adam Stone ccc
Bob Smith ddd
Charles Walls eee


^!SetListDelimiter ^%SPACE%
^!Jump TEXT_START
^!Find "^([^\t]*)\t([^\t]*)\t" RS
^!SetArray %NameArray%=^$GetReSubStrings$
^!Set %FirstName%=^%NameArray1%
^!Set %LastName%=^%NameArray2%
^!Prompt Dear ^%FirstName% ^%LastName%,

     -----------------

I have a find that say looks for this:
^(?<FirstName>[^\t]*)\t(?<LastName>[^\t]*)\t
Basically finds two columns of data separated by a tab (with a following tab).
So I should be able to then insert that in something like:
^!InsertText Dear $<FirstName>,
But it doesn't work.


flo.gehrke@...
 

I am willing to contribute to this topic. However, I don't have any idea of what Don is trying to achieve.

As his line...

^!InsertText Dear $<FirstName>,

shows, he only wants to capture the first names in his list and output them in a salutatory address. Is it a kind of mail merge he tries to produce? If so, why capturing first and last names, assigning them to an array, separating first and last name in another array and so on?

One more time we see that it's rather useless to racken ones brain if we dont have a precise description of the whole task.

As for his original question, Don obviously realized by himself that '$<name>' doesn't work like a %Variable%. It is used to reference a captured named substring '(?<name>)' in a substring replacement. For example, use...

^!Replace "(?<name>Note)Pad" >> "$<name>Tab" RS

to replace 'NotePad' with 'NoteTab'.

Regards,
Flo