How to use the xregexp.forEach 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 bartosz-antosik / vscode-spellright / src / spellright.js View on Github external
// Here split some special cases like: period (`terminal.integrated`),
        // digit (`good2know`), dash (`wp-admin`) etc. Other consequence should
        // be that these words are spelled both as split and as the whole.
        var rother = XRegExp('([^\ \.0-9\-\(\)‘’]+)');
        var rsep = /[\ \.0-9\-\(\)‘’]/;
        var parts = [];

        // We need a phantom split (e.g. for "2sth", "(sth)" case).
        if (rsep.test(word)) {
            parts.push({
                word: '',
                offset: 0
            });
        }

        XRegExp.forEach(word, rother, (match, i) => {
            parts.push({
                word: match[0],
                offset: match.index
            });
        });

        return parts;
    }
github bartosz-antosik / vscode-spellright / src / spellright.js View on Github external
SpellRight.prototype.splitSnakeCase = function (word) {

        // SnakeCase cases: HTML_Script, snake_Case, __test__.
        var rsnake = XRegExp('([^_]+)');
        var rsep = /_/;
        var parts = [];

        // We need a phantom split (e.g. for "_sth: case).
        if (rsep.test(word)) {
            parts.push({
                word: '',
                offset: 0
            });
        }

        XRegExp.forEach(word, rsnake, (match, i) => {
            parts.push({
                word: match[0],
                offset: match.index
            });
        });

        return parts;
    }
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-text / src / utilities.ts View on Github external
static getMatchesSimple(regex: RegExp, source: string): Match[] {

        // Word boundary (\b) in JS is not unicode-aware, so words starting/ending with accentuated characters will not match
        // use a normalized string to match, the return matches' values using the original one
        // http://blog.stevenlevithan.com/archives/javascript-regex-and-unicode
        // https://stackoverflow.com/questions/2881445/utf-8-word-boundary-regex-in-javascript
        let normalized = StringUtility.removeDiacriticsFromWordBoundaries(source);

        let matches = new Array();
        XRegExp.forEach(normalized, regex, match => {
            let groups: { [id: string]: { value: string, index: number, length: number, captures: string[] } } = {};
            let lastGroup = '';

            Object.keys(match).forEach(key => {

                let groupKey = key.substr(0, key.lastIndexOf('__'));
                lastGroup = groupKey;

                if (!groups[groupKey]) {
                    groups[groupKey] = { value: '', index: 0, length: 0, captures: [] };
                }

                if (match[key]) {
                    let index = match.index + match[0].indexOf(match[key]);
                    let length = match[key].length;
                    let value = source.substr(index, length);
github rse / componentjs / doc / component-api.js View on Github external
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;
}

/*  parse first-level structure  */
xre.forEach(txt, xre(
    "([A-Z][^\\n]+)\\n" +    // headline
    "---+[ \\t]*\\n" +       // underlining
    "(.+?\\n)" +             // body
    "(?=[A-Z][^\\n]+?\\n" +  // following headline
    "---+[ \\t]*\\n" +       // corresponding underlining
    "|$)",                   // or at end file
"sg"), function (m) {
    parse2(m[1], m[2]);
});

/*  process first-level structure  */
function parse2 (title, body) {
    /*  generate body headline  */
    html_spec += "<h2>" + mklink(1, title) + "</h2>\n";

    /*  start navigation entry  */
github bartosz-antosik / vscode-spellright / src / spellright.js View on Github external
SpellRight.prototype.splitCamelCase = function (word) {

        // CamelCase cases: HTMLScript, camelCase, CamelCase, innerHTML,
        // start0Case, snake_case, Snake_Case, HOMEToRent.
        var rcamel = XRegExp('(^[\\p{Ll}.@\']+)|[0-9]+|[\\p{Lu}.@\'][\\p{Ll}.@\']+|[\\p{Lu}.@\']+(?=[\\p{Lu}.@\'][\\p{Ll}.@\']|[0-9])|[\\p{Lu}.@\']+');

        var parts = [];
        XRegExp.forEach(word, rcamel, (match, i) => {
            parts.push({
                word: match[0],
                offset: match.index
            });
        });

        return parts;
    }
github akicho8 / shogi-player / src / sfen_parser.js View on Github external
this.attributes["sfen"].split("/").forEach((e, y) =&gt; {
      let x = 0
      XRegExp.forEach(e, XRegExp("(?\\+?)(?\\S)"), (m, i) =&gt; {
        if (/\d+/.test(m.piece)) {
          x += Number(m.piece)
        } else {
          const soldier = new Soldier({
            place: new Place([x, y]),
            piece: Piece.fetch(m.piece),
            promoted: (m.promoted === "+"),
            location: this.__location_by_upper_or_lower_case(m.piece),
          })
          board.place_on(soldier)
          x++
        }
      })
    })
    return board
github noseglid / atom-build / lib / error-matcher.js View on Github external
this.regex.forEach((regex) => {
      if (typeof regex === 'function') {
        regex(this.output).forEach(function (match) {
          this.push(match);
        }.bind(this.currentMatch));
      } else {
        require('xregexp').forEach(this.output, regex, matchFunction.bind(this.currentMatch));
      }
    });
github akicho8 / shogi-player / src / sfen_parser.js View on Github external
get hold_pieces() {
    const _hold_pieces = super.hold_pieces
    if (this.attributes["hold_pieces"] !== "-") {
      XRegExp.forEach(this.attributes["hold_pieces"], XRegExp("(?\\d+)?(?\\S)"), (md, i) =&gt; {
        const piece = Piece.fetch(md.piece_char)
        let count = Number(md.count || 1)
        const location = this.__location_by_upper_or_lower_case(md.piece_char)
        count += _hold_pieces.get(location.key).get(piece.key) || 0
        _hold_pieces.get(location.key).set(piece.key, count)
      })
    }
    return _hold_pieces
  }