Internal lodash utility providing a regular expression for template interpolation delimiters
npx @tessl/cli install tessl/npm-lodash--reinterpolate@3.0.0lodash._reinterpolate is an internal lodash utility module that provides a regular expression for matching template interpolation delimiters. It exports a single RegExp constant used by lodash's template system to identify ERB-style interpolation expressions enclosed in <%= and %> tags.
npm install lodash._reinterpolatevar reInterpolate = require('lodash._reinterpolate');For ES modules:
import reInterpolate from 'lodash._reinterpolate';var reInterpolate = require('lodash._reinterpolate');
// Use the regex to find template interpolation patterns
var template = 'Hello <%=name%>, you have <%=count%> messages.';
var matches = template.match(reInterpolate);
console.log(matches);
// Output: ['<%=name%>', '<%=count%>']
// Extract interpolation expressions
var expressions = [];
var match;
while ((match = reInterpolate.exec(template)) !== null) {
expressions.push(match[1]); // Capture group contains the expression
}
console.log(expressions);
// Output: ['name', 'count']The module exports a single regular expression constant that matches ERB-style template interpolation delimiters.
/**
* Regular expression for matching template interpolation delimiters.
* Matches patterns like <%=expression%> and captures the expression content.
* Pattern: /<%=([\s\S]+?)%>/g
* - <%= : Opening delimiter
* - ([\s\S]+?) : Capture group for any characters including newlines (non-greedy)
* - %> : Closing delimiter
* - g : Global flag for multiple matches
*/
var reInterpolate = /<%=([\s\S]+?)%>/g;The regex pattern /<%=([\s\S]+?)%>/g specifically:
<%=[\s\S]+? (non-greedy)%>g to find all matches in a stringUsage Examples:
var reInterpolate = require('lodash._reinterpolate');
// Simple interpolation matching
var simple = 'Welcome <%=user%>!';
console.log(simple.match(reInterpolate));
// Output: ['<%=user%>']
// Multiple interpolations
var multiple = 'Hello <%=firstName%> <%=lastName%>, you have <%=messageCount%> messages.';
var allMatches = multiple.match(reInterpolate);
console.log(allMatches);
// Output: ['<%=firstName%>', '<%=lastName%>', '<%=messageCount%>']
// Extract just the expressions using capture groups
var expressions = [];
var match;
// Reset regex lastIndex before using exec in a loop
reInterpolate.lastIndex = 0;
while ((match = reInterpolate.exec(multiple)) !== null) {
expressions.push(match[1].trim());
}
console.log(expressions);
// Output: ['firstName', 'lastName', 'messageCount']
// Handle expressions with spaces and complex content
var complex = 'Result: <%= user.name.toUpperCase() %>';
var result = reInterpolate.exec(complex);
console.log(result[1]);
// Output: ' user.name.toUpperCase() '
console.log(result[1].trim());
// Output: 'user.name.toUpperCase()'
// Multiline expressions (supported by [\s\S])
var multiline = `Template with <%=
someFunction() +
anotherValue
%> expression`;
reInterpolate.lastIndex = 0;
var multilineMatch = reInterpolate.exec(multiline);
console.log(multilineMatch[1]);
// Output includes the newlines and whitespaceThis is a minimal utility module with zero dependencies, designed for maximum reusability. The regular expression is specifically crafted for lodash's internal template system but can be used independently for matching ERB-style interpolation patterns in any string.
Key characteristics:
g flag to find all interpolation patterns in a string[\s\S] character class includes newlines for multiline expressions+? ensures minimal matching to avoid capturing multiple expressions as oneCommon patterns:
string.match(reInterpolate) to get all matches as an arrayreInterpolate.exec() in a loop to access capture groupsreInterpolate.lastIndex = 0 before using exec() in loopsmatch[1].trim() to get clean expression content without surrounding whitespace