How to use the xregexp.exec 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 nikhilkalige / docblockr / lib / languages / javascript.js View on Github external
')\\s*' +
        //   var foo = bar '=>' {}
        '=>\\s*'
    );

    var functionRegexMatch = null;
    var methodRegexMatch = null;
    var geterSetterMethodRegexMatch = null;
    var arrowFunctionRegexMatch = null;

    // XXX: Note assignments
    var matches = (
        (functionRegexMatch = xregexp.exec(line, functionRegex)) ||
            (methodRegexMatch = xregexp.exec(line, methodRegex)) ||
            (geterSetterMethodRegexMatch = xregexp.exec(line, geterSetterMethodRegex)) ||
            (arrowFunctionRegexMatch = xregexp.exec(line, arrowFunctionRegex))
    );

    if(matches === null) {
        return null;
    }
    // grab the name out of "name1 = function name2(foo)" preferring name1
    var name = matches.name1 || matches.name2 || '';
    var args = matches.args || matches.arg || null;

    // check for async method to set retval to promise
    var retval = null;
    if (matches.promise) {
        retval = 'Promise';
    } else if (matches.generator) {
        retval = 'Generator';
    }
github nikhilkalige / docblockr / lib / languages / coffee.js View on Github external
CoffeeParser.prototype.parse_var = function(line) {
    //   var foo = blah,
    //       foo = blah;
    //   baz.foo = blah;
    //   baz = {
    //        foo : blah
    //   }
    var regex = xregexp(
        '(?P' + this.settings.varIdentifier + ')\\s*[=:]\\s*(?P.*?)(?:[;,]|$)'
    );
    var matches = xregexp.exec(line, regex);
    if(matches === null)
        return null;

    return [matches.name, matches.val.trim()];
};
github bcoe / onigurumajs / index.js View on Github external
for (var i = 0, pattern; (pattern = splitPattern[i]) !== undefined; i++) {
    if (/\(\?[><][=!]?/.exec(pattern)) {
      patterns.push(currentPattern)
      currentPattern = ''
    }
    currentPattern += pattern
  }
  patterns.push(currentPattern)

  // now apply each pattern.
  for (i = 0, pattern; (pattern = patterns[i]) !== undefined; i++) {
    try {
      if (/\(\?[><][=!]?/.exec(pattern)) {
        result = xregexp.execLb(text, pattern, start)
      } else {
        result = xregexp.exec(text, xregexp(pattern), start)
      }
      if (result) return result
    } catch (e) {
      // we're officially in uncharted territory.
      return null
    }
  }

  return null
}
github sogehige / sogeBot / src / bot / expects.js View on Github external
everything (opts) {
    opts = opts || {}
    _.defaults(opts, { optional: false })
    if (!opts.optional) this.checkText({
      expects: 'any',
      ...opts,
    })

    const regexp = XRegExp(`(? .* )`, 'ix')
    const match = XRegExp.exec(` ${this.text} `, regexp)
    if (!_.isNil(match)) {
      this.match.push(match.everything.substring(1, match.everything.length - 1).trim())
      this.everything = this.text.replace(match.everything, '') // remove from text matched pattern
    } else {
      if (!opts.optional) throw Error('There is no text found.')
      else this.match.push(null)
    }
    return this
  }
github microsoft / DevSkim-VSCode-Plugin / server / src / devskimWorker.ts View on Github external
problems.push(problem);
                        }
                        //throw a pop up if there is a review/suppression comment with the rule id, so that people can figure out what was
                        //suppressed/reviewed
                        else if (!suppressionFinding.noRange && includeSuppressions) 
                        {
                            //highlight suppression finding for context
                            //this will look
                            let problem: DevSkimProblem = this.MakeProblem(rule, DevskimRuleSeverity.WarningInfo, suppressionFinding.suppressionRange,"", range);

                            problems.push(problem);

                        }
                        //advance the location we are searching in the line
                        matchPosition = match.index + match[0].length;
                        match = XRegExp.exec(documentContents, matchPattern, matchPosition);
                    }
                }
            }
        }
        return problems;
    }
github ddycai / chord-transposer / index.js View on Github external
function parse(sym) {
  return XRegExp.exec(sym, chordRegex);
}
github microsoft / DevSkim-VSCode-Plugin / server / src / devskimWorker.ts View on Github external
//look for the suppression comment for that finding
            if (DocumentUtilities.MatchIsInScope(langID, documentContents.substr(0, match.index), newlineIndex, condition.pattern.scopes)) 
            {
                if (condition.negateFinding == true) 
                {
                    return false;
                }
                else 
                {
                    foundPattern = true;
                    break;
                }
            }
            startPos = match.index + match[0].length;
            match = XRegExp.exec(documentContents, conditionRegex, startPos);
        }
        if (condition.negateFinding == false && foundPattern == false) 
        {
            return false;
        }
        

        return true;
    }
github sogehige / sogeBot / src / bot / systems / cooldown.ts View on Github external
async toggle (opts: Record, type: string) {
    const match = XRegExp.exec(opts.parameters, constants.COOLDOWN_REGEXP) as unknown as { [x: string]: string } | null;

    if (_.isNil(match)) {
      const message = await prepare('cooldowns.cooldown-parse-failed');
      sendMessage(message, opts.sender, opts.attr);
      return false;
    }

    const cooldown = await getRepository(CooldownEntity).findOne({
      relations: ['viewers'],
      where: {
        name: match.command,
        type: match.type as 'global' | 'user',
      },
    });
    if (!cooldown) {
      const message = await prepare('cooldowns.cooldown-not-found', { command: match.command });
github nikhilkalige / docblockr / lib / languages / sass.js View on Github external
SassParser.prototype.parse_arg = function(arg) {

    var regex = xregexp(
        '(?P' + this.settings.varIdentifier + ')(\\s*:\\s*(?P.*))?'
    );

    return xregexp.exec(arg, regex);
};