RegEx bug

I'm using the "Text Replace" action on a text file, and trying to combine FB variables and match substitution in my output. It looks very much as though FB loses the first character of the variable in this case. In my case:

Input line: "OutputFilename" = "8:Debug\\CipherWebServiceSetup6.5.0.msi"

Find regex:  (OutputFilename.*CipherWebServiceSetup)([\.\d]+)

Replace regex:  $1%ASSEMBLY_VERSION%.

Where %ASSEMBLY_VERSION% is:  7.0.0.0

I get this line:  "OutputFilename" = "8:Debug\\CipherWebServiceSetup.0.0.0.msi"

Note the missing 7.

 

To confirm I put a replace expression like this in:

    $0

    $1

    $2

    %ASSEMBLY_VERSION%

    $1%ASSEMBLY_VERSION%

And get this:

 

"OutputFilename" = "8:Debug\\CipherWebServiceSetup6.5.0.
OutputFilename" = "8:Debug\\CipherWebServiceSetup
6.5.0.

7.0.0.5
.0.0.5msi"

In this case I can live with an extra dot in the output, so I just made the replace expression $1.%ASSEMBLY_VERSION% and it works well enough for me.

 

I think there's also a minor gotcha in the help - in "Text Find / Replace Action" there's an image of some script. Ideally that would be text so it can be copied and pasted. But when I ran it VBScript barfed on double quotes inside the string, which I found confusing. ie, in the example above I get a VBScript exception and an offer to debug it using VS. I'm not sure what's going on there.

Later: OK, it's actually more hideous than that, if I make the variable 77.0.0.0 in an effort to work around this both digits vanish. And above it looks as though $1 does not appear either. So my "add a dot between $1 and %foo%" seems to be the only work-around right now.

I think all that’s happening here is that you’re attempting to replace with the text “$17.0.0.0” and FinalBuilder is attempting to substitute in the 17th matching subsexpression, and failing. I think it’s a bug, because afaik, the regular expression engine being used will never generate more than 9 subexpressions anyway. I can’t think of any way of getting around this problem: you need to insert an extra character (like the dot), then find/replace that in a second step.

Alternatively you could use JavaScript to do the search/replace rather than the FB action.

For the documentation “gotcha”, the code is JScript, not VBScript…

Steve

Oh, there is a simple solution.

Make your replacement text: ${1}%ASSEMBLY_VERSION%.

Steve

Hi guys,

Steve is right, this is an annoyance when trying to use backreferences with numeric variables. The workaround he describes should work. Sorry for the inconvenience.

Regards,

Angus

The other workaround is to remove some of the “known” text from the first matching group so you have something to put between $1 and the numeric value, ie

Input line: “OutputFilename” = “8:Debug\CipherWebServiceSetup6.5.0.msi”

Find regex: (OutputFilename.*)CipherWebServiceSetup([.\d]+)

Replace regex: $1CipherWebServiceSetup%ASSEMBLY_VERSION%.

Angus, that’s exactly what I have done and it works as expected. Thanks both of you.

Documentation: can you make it copyable text?

Hi Moz,

You mean the "OnFindText" part? We can't really make that copyable text, because it's only really intended to be a screenshot to show you where to look for that script event, and the kind of things you might do with it. Therefore it needs to be an image.

As Steve pointed out, FB was unhappy because the script shown is JScript. If you need VBScript, it will look like this:

Action.SendLogMessage "Found " & FoundText & " at " & Offset


Regards,

Angus