refactor: improve regex patterns with comments to document

This commit is contained in:
Sanjai Kumar 2024-12-11 13:25:31 +05:30
parent 637b7090ed
commit 4189dbf134

View File

@ -58,9 +58,14 @@ const addSuffixToDuplicateName = (item, index, allItems) => {
return nameSuffix !== 0 ? `${item.name}_${nameSuffix}` : item.name; return nameSuffix !== 0 ? `${item.name}_${nameSuffix}` : item.name;
}; };
const regexVariable = new RegExp('{{.*?}}', 'g'); // Matches any string that starts with '{{' and ends with '}}', capturing everything in between.
const regexToRemove = new RegExp('(?:_\\.|[\\s\\]]+)', 'g'); const regexVariable = /{{.*?}}/g;
const regexToUnderscore = new RegExp('[.\\[]', 'g');
// Matches any sequence that starts with '_', followed by a dot '.', and then one or more whitespace characters or closing square brackets.
const regexToRemove = /(?:_\.[\s\]]+)/g;
// Matches any dot '.' or opening square bracket '['.
const regexToUnderscore = /[.\[]/g;
const normalizeVariables = (value = "") => { const normalizeVariables = (value = "") => {
const variables = value.match(regexVariable) || []; const variables = value.match(regexVariable) || [];