I think I found the place in the code, similar to your example but with some changes. From what I gather I can use the string.replace as a starting point for my function. Since the repl parameter in the .replace can also be a function. See below, sound correct?if (queryLayer)
{
var query:Query = new Query();
var myPattern:RegExp = /\[value\]/g;
var expr:String;
// adds quotes to the string to be used for SQL query
value = value.replace("'","''");
expr = queryExpr.replace(myPattern, mySubStringFunctionResult);
query.where = expr;
query.outSpatialReference = map.spatialReference;
if(queryDefExpr != "")
queryLayer.definitionExpression = queryDefExpr;
queryLayer.queryFeatures(query, new AsyncResponder(onResult, onFault, queryFields));
showMessage(loadingLabel, true);
showStateResults();