Can you be a bit more specific about how the schema is being sourced and “materialised”? Saying “propertysets / flow variables (e.g. via eval)” is still pretty vague — the exact retrieval path matters a lot here.
I tried to reproduce this in Apigee Edge using a JS policy <Properties> (available via the built-in properties object). I tested both materialisation approaches: eval() and JSON.parse() (and yes — please don’t use eval in real code). In both cases, the backslash is preserved before new RegExp(), and the regex works as expected, so this doesn’t look like a Rhino limitation.
Properties:
<Properties>
<Property name="schema">{"x": { "pattern": "^7\\d{9}$", "maxLength": 10, "type": "string", "nullable": true }}</Property>
</Properties>
Test code:
// JavaScript-1.js (Apigee Edge / Rhino)
// Compare eval() materialisation vs JSON.parse() materialisation
context.setVariable('debug.started', true);
var schemaJsonString = properties.schema;
context.setVariable('debug.schema.present', !!schemaJsonString);
context.setVariable('debug.schema.raw', schemaJsonString);
// ---------- Path A: eval() ----------
var objEval = eval('(' + schemaJsonString + ')');
var patternEval = objEval.x.pattern;
context.setVariable('debug.eval.pattern.raw', patternEval);
context.setVariable(
'debug.eval.pattern.charcodes',
patternEval.split('').map(function (c) { return c.charCodeAt(0); }).join(',')
);
var reEval = new RegExp(patternEval);
// ---------- Path B: JSON.parse() ----------
var objJson = JSON.parse(schemaJsonString);
var patternJson = objJson.x.pattern;
context.setVariable('debug.json.pattern.raw', patternJson);
context.setVariable(
'debug.json.pattern.charcodes',
patternJson.split('').map(function (c) { return c.charCodeAt(0); }).join(',')
);
var reJson = new RegExp(patternJson);
// ---------- Test ----------
var value = context.getVariable('request.queryparam.value');
context.setVariable('debug.value', value);
context.setVariable('debug.eval.match', reEval.test(value));
context.setVariable('debug.json.match', reJson.test(value));
Output:
debug.started true
debug.schema.present true
debug.schema.raw {"x": { "pattern": "^7\\d{9}$", "maxLength": 10, "type": "string", "nullable": true }}
debug.eval.pattern.raw ^7\d{9}$
debug.eval.pattern.charcodes 94,55,92,100,123,57,125,36
debug.json.pattern.raw ^7\d{9}$
debug.json.pattern.charcodes 94,55,92,100,123,57,125,36
request.queryparam.value 7123456789
debug.value 7123456789
debug.eval.match true
debug.json.match true