Kinook Software Forum

Kinook Software Forum (https://www.kinook.com/Forum/index.php)
-   [VBP] General Discussion (https://www.kinook.com/Forum/forumdisplay.php?f=2)
-   -   Passing regex match to a script function (https://www.kinook.com/Forum/showthread.php?t=580)

MHolmes 09-27-2004 04:14 PM

Passing regex match to a script function
 
In a Replace Files step, I need to pass the result of a regex match. Basically, I need to match a filename in a file using the following regex:

Code:

^.*"OutputFilename"\s*=\s*"(.*)".*$
I capture the complete path specified, but I want to get JUST the filename part (so if it's C:\My Files\somefile.txt, I want somefile.txt) so that I can mutate the final output path at build time. I have a project level function called GetFileNamePart which uses the FSO to return the filename, but I can't call it as:

Code:

[GetFileNamePart($1)]
In the replace text. I know that regexp normally uses backreferences for that, but how can I get a match and pass it to a script function?

kevina 09-29-2004 12:03 PM

Unfortunately you can't do exactly what you are wanting (pass a matched expression to script), but you can accomplish what you are trying to do with just a regular expression.

Below is an example Replace In File step that uses a different regular expression that does what I think you are trying to do.


c:\temp\test.txt
c:\temp\output.txt
(^[[^\n"]]*"OutputFilename"\s*=\s*)"(([[^\n\\"]]*\\)*)([[^"\n]]*)[["\n]]
$1"(?3$4)"
1
Replace Full Path with filename only


Note: Please note that using .* is not a very safe thing to do with regular expressions in Visual Build Pro because it doesn't function in a 'line mode'. .* is greedy in Visual Build Pro which can consume line feeds. The sample regular expression above adheres to the advice in the help file for Replace In File Action using [^\n]* instead of .*.

Note 2: Just copy the above xml fragment and paste into Visual Build Pro. A Replace In File step will be created for you to review/use.


All times are GMT -5. The time now is 12:46 PM.


Copyright © 1999-2023 Kinook Software, Inc.