RegExp match of string with square bracket
If you have JScript 5.5 or higher installed, here's some code that lets you
substitute any expression in ASP-like fashion from a template file:
var fso = Server.CreateObject("Scripting.FileSystemObject");
var ts = fso.OpenTextFile("c:\\path\\to\\template.txt");
var text = ts.ReadAll();
ts.Close();
text = text.replace( /\<\%(=?)((.|\n)*?)\%\>/g,
function(ss,eq,ex){return eq? eval(ex):(eval(ex),"");});
A template.txt file might look like:
The amount you entered was <%=Request.Form("amount").Item%>,
the current time is <%=(new Date).toString()%>.
If you want you can declare variables above the block of code that does the
substitution and they can be used in the template.
Quote:
> I'm trying to use the replace method on the string object to replace
> strings with square bracket arount them.
> For example, if I want to replace the string [amount] with $125.00 in
> the following string:
> "Your loan amount is [amount] plus interest"
> How would I build my regular expression? The square bracket have a
> special meaning but padding them with the \ character doesn't seem to
> make a difference.
> Thanks!