How to use the xregexp.replace function in xregexp

To help you get started, we’ve selected a few xregexp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rse / componentjs / doc / component-api.js View on Github external
function conv (anchor, txt) {
    /*  convert types  */
    txt = xre.replace(txt, xre("R&lt;([^/].*?)&gt;", "sg"), function (m0, m1) { return "<span class="\&quot;R\&quot;">" + mklink(anchor, m1) + "</span>"; });
    txt = xre.replace(txt, xre("M&lt;([^/].*?)&gt;", "sg"), function (m0, m1) { return "<span class="\&quot;M\&quot;">" + mklink(anchor, m1) + "</span>"; });
    txt = xre.replace(txt, xre("P&lt;([^/].*?)&gt;", "sg"), "<span class="\&quot;P\&quot;">$1</span>");
    txt = xre.replace(txt, xre("F&lt;([^/].*?)&gt;", "sg"), "<span class="\&quot;F\&quot;">$1</span>");
    txt = xre.replace(txt, xre("T&lt;([^/].*?)&gt;", "sg"), "<span class="\&quot;T\&quot;">$1</span>");
    txt = xre.replace(txt, xre("O&lt;([^/].*?)&gt;", "sg"), "<span class="\&quot;O\&quot;">$1</span>");
    txt = xre.replace(txt, xre("C&lt;([^/].*?)&gt;", "sg"), "<code>$1</code>");
    txt = xre.replace(txt, xre("I&lt;([^/].*?):(\\d+)&gt;", "sg"), "<img width="\&quot;$2\&quot;/" src="\&quot;$1\&quot;" style="\&quot;float:">");

    /*  convert typography aspects  */
    txt = xre.replace(txt, xre("-&gt;", "sg"), "→");
    txt = xre.replace(txt, xre("&lt;-", "sg"), "←");
    txt = xre.replace(txt, xre("--", "sg"), "—");
    txt = xre.replace(txt, xre("(FIXME|TODO)", "sg"), "<span class="\&quot;$1\&quot;">$1</span>");

    return txt;
}
github rse / componentjs / doc / component-api.js View on Github external
function parse4 (title, synopsis, body) {
            html_spec += "<li>";

            /*  parse fifth-level structure (part 1)  */
            var txt = synopsis;
            txt = xre.replace(txt, xre("M&lt;(.+?)&gt;", "sg"), function (m0, m1) {
                parse5a(title, m1);
            });

            /*  process fifth-level structure  */
            function parse5a (title, txt) {
                if (!cache[title + ":" + txt]) {
                    html_navi += "</li><li>" + mklink(0, txt) + "</li>";
                    cache[title + ":" + txt] = true;
                }
            }

            /*  generate synopsis  */
            html_spec += "<div class="\&quot;synopsis\&quot;">";
            synopsis = xre.replace(synopsis, xre("[ \\t]{2,}", "sg"), " ");
            synopsis = conv(1, synopsis);
            synopsis = xre.replace(synopsis, xre("(\\[|\\]|:|\\s+=\\s+)", "sg"), "<span class="\&quot;meta\&quot;">$1</span>");</div>
github sogehige / sogeBot / src / bot / systems / moderation.ts View on Github external
}
    }

    text = ` ${text} `;
    const whitelist = this.cListsWhitelist;

    for (const value of whitelist.map(o => o.trim().replace(/\*/g, '[\\pL0-9\\S]*').replace(/\+/g, '[\\pL0-9\\S]+'))) {
      if (value.length > 0) {
        let regexp;
        if (value.startsWith('domain:')) {
          regexp = XRegExp(` [\\S]*${XRegExp.escape(value.replace('domain:', ''))}[\\S]* `, 'gi');
        } else { // default regexp behavior
          regexp = XRegExp(` [^\\s\\pL0-9\\w]?${value}[^\\s\\pL0-9\\w]? `, 'gi');
        }
        // we need to change 'text' to ' text ' for regexp to correctly work
        text = XRegExp.replace(` ${text} `, regexp, '').trim();
      }
    }
    return text.trim();
  }
github rse / componentjs / doc / component-api.js View on Github external
var txt = synopsis;
            txt = xre.replace(txt, xre("M&lt;(.+?)&gt;", "sg"), function (m0, m1) {
                parse5a(title, m1);
            });

            /*  process fifth-level structure  */
            function parse5a (title, txt) {
                if (!cache[title + ":" + txt]) {
                    html_navi += "<li>" + mklink(0, txt) + "</li>";
                    cache[title + ":" + txt] = true;
                }
            }

            /*  generate synopsis  */
            html_spec += "<div class="\&quot;synopsis\&quot;">";
            synopsis = xre.replace(synopsis, xre("[ \\t]{2,}", "sg"), " ");
            synopsis = conv(1, synopsis);
            synopsis = xre.replace(synopsis, xre("(\\[|\\]|:|\\s+=\\s+)", "sg"), "<span class="\&quot;meta\&quot;">$1</span>");
            synopsis = xre.replace(synopsis, xre(";", "sg"), "</div><div class="\&quot;synopsis\&quot;">");
            synopsis = xre.replace(synopsis, xre("\\(\\s+", "sg"), "(");
            synopsis = xre.replace(synopsis, xre("\\s+\\)", "sg"), ")");
            html_spec += synopsis + "\n";
            html_spec += "</div>";

            /*  parse fifth-level structure (part 2)  */
            txt = body + "\n";
            txt = xre.replace(txt, xre(
                "(.+?\\n)" +
                "(?= \\n | $ )",
            "sgx"), function (m0, m1) {
                parse5b(m1);
            });
github rse / componentjs / doc / component-api.js View on Github external
body = xre.replace(body, xre(
        "^(.+?\\n)" +           // intro paragraph
        "(?=\\n-[ \\t]+\\S+)",  // start of first function
    "s"), function (m0, m1) {
        html_spec += "<div class="\&quot;intro\&quot;">" + addpara(conv(0, m1)) + "</div>";
    });
    function addpara (txt) {
        txt = xre.replace(txt, xre("(\\n).[ \\t]+([^\\n]*(?:\\n[ \\t]+[^\\n]+)*)", "sg"), "$1<li>$2</li>");
        txt = xre.replace(txt, xre("(\\n\\n)(<li>)", "sg"), "$1<ul>$2");
        txt = xre.replace(txt, xre("(&lt;\/li&gt;)(\\n\\n)", "sg"), "$1</ul>$2");
        txt = xre.replace(txt, xre("\\n{2,}", "sg"), "<p>\n");
        return txt;
    }

    /*  parse second-level structure (part 2)  */
    body = xre.replace(body, xre(
        "-[ \\t]+(\\S+.+?)" +  // function start
        "(?=-[ \\t]+\\S+" +    // start of next function
        "|$)",                 // or end of file
    "sg"), function (m0, m1) {
        parse3(title, m1);
    });

    /*  process third-level structure  */
    function parse3 (title, body) {
        html_spec += "</p><ul>\n";

        /*  parse forth-level structure  */
        body = xre.replace(body, xre(
            "^" +
            "(.+?)\\n" +  //  synopsis
            "\\n" +       //  blank line</ul></li>
github streetsidesoftware / cspell / packages / cspell-tools / dist / text.js View on Github external
function splitCamelCaseWord(word) {
    const wPrime = word.replace(regExUpperSOrIng, s =&gt; s[0] + s.substr(1).toLowerCase());
    const separator = '_&lt;^*_*^&gt;_';
    const pass1 = XRegExp.replace(wPrime, regExSplitWords, '$1' + separator + '$2');
    const pass2 = XRegExp.replace(pass1, regExSplitWords2, '$1' + separator + '$2');
    return XRegExp.split(pass2, separator);
}
exports.splitCamelCaseWord = splitCamelCaseWord;
github mattermost / mattermost-webapp / utils / text_formatting.jsx View on Github external
function autolinkEmails(text, tokens) {
    function replaceEmailWithToken(fullMatch, prefix, email) {
        const index = tokens.size;
        const alias = `$MM_EMAIL${index}$`;

        tokens.set(alias, {
            value: `<a href="mailto:${email}" class="theme">${email}</a>`,
            originalText: email,
        });

        return prefix + alias;
    }

    let output = text;
    output = XRegExp.replace(text, reEmail, replaceEmailWithToken);

    return output;
}
github rse / componentjs / doc / component-api.js View on Github external
function mkid (id) {
    id = id.toLowerCase();
    id = xre.replace(id, xre("\\s+", "sg"), "_");
    id = xre.replace(id, xre("-", "sg"), "_");
    return id;
}