How to use the replace function from xregexp
Find comprehensive JavaScript xregexp.replace code examples handpicked from public code repositorys.
GitHub: apostrophecms/apostrophe
96 97 98 99 100 101 102 103 104 105
function tmpl(c) { return c.toUpperCase() !== c.toLowerCase() ? 'A' : ' '; } ; let template = str.slice(0, length + 1); template = XRegExp.replace(template, regex, tmpl); // 'Hello, world' -> 'HellAA AAAAA' if (template.slice(template.length - 2).match(/\w\w/)) { template = template.replace(/\s*\S+$/, ''); } else {
544
0
125
11 12 13 14 15 16 17 18 19
// XRegExp.replace allows named backreferences in replacements var format = XRegExp.replace('2005-01-22', date, '${day}/${month}/${year}'); console.log(format); // -> '22/01/2005' var formatf = XRegExp.replace('2005-01-22', date, function(match) { return `${match.day}/${match.month}/${match.year}`; }); console.log(formatf); // -> '22/01/2005'
1
0
2
+ 3 other calls in file
xregexp.exec is the most popular function in xregexp (52 examples)