Regular expression backreference

There is something wrong with the numbering of regular expression back references, they off by 1. The normal numbering is that the text the expression is working on gets the reference $0, the first () gets $1 and so on.
In Tinderbox Version 9.5.2 (b606) I get $1 for the entire expression, $2 for the first () group.

Are you sure? Consider note ‘test’ with this $Text:

Now note ‘example’ with this $Edict and result as shown:

$Text is match 0, i.e. the whole match string and $1 and $2 go to attributes as per the edict code. Here’s my test file: backref-text.tbx (115.7 KB)

Note this from Using regular expression back-references :

From v9.5.0, if(){…} and if(){…} else {…} now restore regular expression back-references ($1, $2…) to their state prior to the next if() statement.

So, it may be you have code that unwittingly relied on the bug fixed above.

Do you have an example file demonstrating the problem you’re reporting?

$0 is bound to the entire matched expression. $1 is bound to the first back-reference.

1 Like

First: I cannot repeat my results from yesterday. Today regex is back to normal working order for $0,$1 etc.
Yesterday I had a case (from Tinderbox Manual 9.2.0, bottom of page 62) testing
Query: Text(^Color:(\w+)\b$) and Action $Color=$1
(this part of a larger tbx-file) and I could verify by text output of the backlinks that they were off by one.
Today, building just a tbx with one note and one agent works perfectly.
So, lets close this and enjoy the correct workings of Tinderbox.

1 Like

I see the original issue is now closed, but FWIW for later readers…

The examples above from v9.2.0 Help uses action syntax retired in v5 era, so that might be the issue. The current v9.5.2 Help (in article ‘Text Patterns’ sub-section ‘Parentheses’) the example code has been updated to use current syntax.

Thank you for replying.
I think I also found my error.
In the Query, that should be Text(^Color:(\w+)\b$), was instead Text((^Color:(\w+)\b$)). Normally parenteses could be stacked but, of course, here after the first opening parentese the expectation is a regular expression, and in this case it starts with an opening parentheses shifting the count of everything one step up.

1 Like