Repository navigation
Feature/2580 support regex for templating - #2668
Merged
JoernBerkefeld merged 3 commits intoOct 4, 2026
Merged
Conversation
Coverage ReportCommit:721e988Base: develop@5d878a7 Details (changed files):
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR details
What changes did you make? (Give an overview)
Further details (optional)
Regex market variables
Existing scalar market variables remain compatible: strings, numbers, and booleans use the existing literal replacement behavior. You can mix scalar variables and regex objects in the same market. The special handling of
descriptionand the existing fallback behavior remain unchanged.For more selective matches, configure a variable as an object:
search: a JavaScript regular expression source, without/delimiters or flags. It is applied globally when building a template (buildTemplate/bt), replacing every match.replace: a literal string, number, or boolean used when building a definition (buildDefinition/bd). It is not a JavaScript capture-group replacement expression.template(optional): a native JavaScript replacement string used when building the template. Capture references such as$1and$2preserve parts of the match. If omitted, it defaults to{{{key}}}, wherekeyis the market variable's name.Match an exact quoted value
The following
.mcdevrc.jsonexample matches the complete quoted value"Dynamic"rather than every occurrence ofDynamic:{ "markets": { "source": { "senderProfile": { "search": "(\")Dynamic(\")", "replace": "Dynamic", "template": "$1{{{senderProfile}}}$2" } }, "target": { "senderProfile": { "search": "(\")Transactional(\")", "replace": "Transactional", "template": "$1{{{senderProfile}}}$2" } } } }The first and second capture groups contain the surrounding quotes. The replacement
$1{{{senderProfile}}}$2therefore produces"{{{senderProfile}}}", keeping the JSON template valid. Values such as"Dynamic Sender Profile"and"OrderConfirmationDynamic_DEV"remain unchanged. Building with the source market restores"Dynamic"; building with the target market produces"Transactional". The target'ssearchlets that value be templated again using the same variable.Match a sender profile field prefix
To replace only the local-part prefix in
FromAddress, while leaving occurrences in other fields alone, use this.mcdevrc.jsonexample:{ "markets": { "source": { "regex": { "search": "(\"FromAddress\":\\s*\")joern", "replace": "joern", "template": "$1{{{regex}}}" } }, "target": { "regex": { "search": "(\"FromAddress\":\\s*\")thuy", "replace": "thuy", "template": "$1{{{regex}}}" } } } }For example,
"FromAddress":"[email protected]"becomes"FromAddress":"{{{regex}}}@example.com". The capture group preserves the field name, colon, optional whitespace, and opening quote; the domain and closing quote are outside the match and stay intact. Building for the source restores[email protected]; building for the target produces[email protected].Important: match the text mcdev actually searches. JSON metadata is searched as compact
JSON.stringifyoutput, not the pretty-printed file on disk. There is no space after a colon in that serialized output, so a pattern containing the literal space in"FromAddress": "joernwill not match it. The JSON regex source"(\"FromAddress\":\\s*\")joern"allows zero whitespace as well as whitespace when present. Write\\s*in JSON so the parsed regular expression receives\s*.Embedded newlines in JSON string values are escaped in the serialized metadata; they are not actual line breaks for a whitespace regex to match. Extracted code files, on the other hand, retain actual whitespace and newlines, so
\s*can match those characters there.These are text-only replacements. A numeric or boolean
replacevalue renders as text; native JSON type-preserving templating of number or boolean fields is out of scope. Keep the surrounding syntax valid, including quotes and any required escaping in JSON strings.Checklist