Re: odd behavior in ^$StrAlign("Str";TextWidth;Alignment[;Pad=False])$ (added in v4.9)
- Hi Flo,
Don has already answered your question. But let me put my own spin on it.
When NoteTab parses the function which takes its input ("$1") and modifies it by adding spaces. In other words, the function passes the literal string '$1' through, along with the additional spaces.
So the regular expression sees the output of the function:
" $1 "
which is a perfect pattern, into which to insert each group content.
i.e. (used monospaced text to align the before and after):
" $1 " becomes:
" 234 data "
Your example with StrCopy works exactly the same way. StrCopy copies up to the 4 characters you told it to copy, and passes them to the regular expression. Since the string contains only "$1" it passes that out to the regexp engine, which sees it as a replacement token.
(1) --> "$1 plus" --> "1 plus"
(12) --> "$1 plus" --> "12 plus"
(234)--> "$1 plus" --> "234 plus"
One more thing. Suppose the str function is in the search pattern. It too will only get parsed once, and the result passed to the regexp engine. However, most of the time you will probably not have a group passed into the function to confuse the issue.
Though you could (using \1).
--- In email@example.com, "flo.gehrke" <flo.gehrke@...> wrote:
> > NoteTab will parse the StrAling function only once...
the dingaling wrote stringaling
> Eb, I've got some problems with that explanation. Let's look at...
> ^!Replace "^(\d+) " >> "^$StrAlign("$1";5;Right)$ " RAWS
> On the other hand, if we look at...
> ^!Replace "^(\d+)" >> "^$StrCopy("$1";1;4)$ plus" WARS
- --- In firstname.lastname@example.org, "Eb" <ebbtidalflats@...> wrote:
>Don & Eb,
> Hi Flo,
> Don has already answered your question. But let me put my own spin on it...
Thanks for your replies!
Now the penny has dropped for me. My point was that I was confused by Eb's statement...
> (NT) parses "$1" as a literal dollar sign followed by the numeral 1.I misunderstood this sentence as if '$1' would loose its capability to work as a kind of variable. That is, it would have the same effect as writing...
> A two character wide string.
^!Replace "^(\d+)" >> "^$StrAlign("XY";5;Right)$" RAWS
which would end up with...
without inserting any numbers. As a consequence of this misunderstanding I wondered: "Where do the numbers come from if it's only a string?".
Thanks to your explanations it's clear now!