How to use the oniguruma.OnigRegExp function in oniguruma

To help you get started, we’ve selected a few oniguruma 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 atom / first-mate / src / grammar.js View on Github external
this.emitter = new Emitter()
    this.repository = null
    this.initialRule = null

    this.rawPatterns = patterns
    this.rawRepository = repository

    if (injectionSelector) {
      this.injectionSelector = new ScopeSelector(injectionSelector)
    } else {
      this.injectionSelector = null
    }

    if (firstLineMatch) {
      this.firstLineRegex = new OnigRegExp(firstLineMatch)
    } else {
      this.firstLineRegex = null
    }

    if (!this.fileTypes) { this.fileTypes = [] }
    this.includedGrammarScopes = []

    // Create last since Injections uses APIs from this class
    this.injections = new Injections(this, injections)
  }
github bpaquet / node-logstash / lib / filters / filter_grok.js View on Github external
FilterGrok.prototype.expandGrokPattern = function(regex, extra_patterns) {
  var offset = 0;
  var reduced = regex;
  var result;
  var grokFinder = new OnigRegExp('%{[^}]+}');
  var grokParts = new RegExp('%{([^:]+):?(.*)}');

  while ((result = grokFinder.searchSync(regex, offset))) {
    offset = result[0].end;
    var grokExp = result[0].match;
    var parts = grokExp.match(grokParts);

    var p = global_patterns[parts[1]] || extra_patterns[parts[1]];
    if (p) {
      if (parts[2].length > 0) {
        this.fields.push(parts[2]);
      }
      var reg = this.expandGrokPattern(p, extra_patterns);
      if (parts[2].length > 0) {
        // create a named capturing group
        reg = '(?<' + parts[2] +  '>' + reg + ')';
github Beh01der / node-grok / lib / index.js View on Github external
t.parseSync = function(str) {
        if (!t.regexp) {
            t.regexp = new OnigRegExp(t.resolved);
        }

        var result = t.regexp.searchSync(str);

        if(!result)
            return null;

        var r = {};

        result.forEach(function(item, index) {
            var field = t.fields[index];
            if(field && item.match) {
                r[field] = item.match;
            }
        });
github atom / atom / src / text-mate-language-mode.js View on Github external
regexForPattern(pattern) {
    if (pattern) {
      if (!this.regexesByPattern[pattern]) {
        this.regexesByPattern[pattern] = new OnigRegExp(pattern);
      }
      return this.regexesByPattern[pattern];
    }
  }
github bpaquet / node-logstash / lib / filters / filter_grok.js View on Github external
var _done = function(extra_patterns) {
    try {
      var expanded = this.expandGrokPattern(this.grok, extra_patterns);
      this.regex = new OnigRegExp(expanded);
    }
    catch(e) {
      logger.error('Unable to process grok pattern', this.grok, e);
      return callback(e);
    }
    callback();
  }.bind(this);
github Beh01der / node-grok / lib / index.js View on Github external
t.parse = function(str, next) {
        if (!t.regexp) {
            t.regexp = new OnigRegExp(t.resolved);
        }

        t.regexp.search(str, function(err, result) {
            if(err || !result)
                return next(err, result);

            var r = {};

            result.forEach(function(item, index) {
                var field = t.fields[index];
                if(field && item.match) {
                    r[field] = item.match;
                }
            });

            return next(err, r, result);