How to use the xregexp.matchRecursive 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 GreenImp / rpg-dice-roller / src / dice-roll.js View on Github external
static parseNotation(notation){
      const parsed = [];

      // only continue if a notation was passed
      if(notation) {
        // build the regex for matching a die (including exploding and pool dice etc. notation)
        const dieRegex = DiceRoll.notationPatterns.get('dieFull', 'g');

        // split the notation into its parenthesis groupings
        const groups = XRegExp.matchRecursive(
          notation,
          '\\(', '\\)',
          'g',
          {
            valueNames: [
              'between', 'left', 'match', 'right',
            ],
          }
        );

        // loop through each group and parse it
        groups.forEach(group => {
          if (group.name === 'match') {
            // this is a match within the parenthesis group (ie. `3d6+2` in `(3d6+2)*4`
            // recursively parse it in case it has nested parenthesis
            parsed.push(DiceRoll.parseNotation(group.value));
github TheSharks / JagTag-JS / index.js View on Github external
const matchRecursive = str => XRegExp.matchRecursive(str, '{', '}', 'gi')
github jsoverson / preprocess / lib / preprocess.js View on Github external
function matchReplacePass(content) {
    var matches = XRegExp.matchRecursive(content, rule.start, rule.end, 'gmi', {
      valueNames: ['between', 'left', 'match', 'right']
    });

    var matchGroup = {
      left: null,
      match: null,
      right: null
    };

    return matches.reduce(function (builder, match) {
      switch(match.name) {
        case 'between':
          builder += match.value;
          break;
        case 'left':
          matchGroup.left = startRegex.exec(match.value);