How to use the xregexp.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 azukiapp / azk / src / manifest / system.js View on Github external
return _.reduce(ports, (ports, port, name) => {
      port = XRegExp.exec(port, regex_port);
      port.protocol = port.protocol || "tcp";

      // TODO: Add support a bind ip
      var conf = { HostIp: config("agent:dns:ip") };
      if (port.public)
        conf.HostPort = port.public;

      ports[name] = {
        config : conf,
        name   : port.private + "/" + port.protocol,
        private: port.private
      };
      return ports;
    }, {})
  }
github antitoxic / node-reversable-router / route.js View on Github external
Route.prototype.match = function (url) {
  //make sure the last `/` is trimmed off the url, otherwise last splash can falsely be empty string, i.e. ''
  if (url.slice(-1) == '/') {
    url = url.slice(0, -1);
  }
  var path = this.path;

  // Matches url?
  // Performance: If there isn't any regex characters `*:()` then simply check for equality
  if (path.indexOf('*') == -1 && path.indexOf(':') == -1 && path.indexOf('(') == -1 && path.indexOf(')') == -1 && path == url) {
    return true;
  }
  var regex = this.regex ? this.regex : this.compile();
  var matches = XRegExp.exec(url, regex);
  if (matches == null) return false;

  // Initialise the return value (found parameters)
  var self = this;
  var RequestParams = {_masked:[]};

  // All named parameters
  self.params.forEach(function (param) {
    if (matches[param] == undefined) return;
    RequestParams[param] = matches[param];
  });

  // All masked/unnamed parameters
  var masked = self.masked;
  masked.every(function (maskedName) {
    if (matches[maskedName] == undefined) return true;
github mozilla-b2g / gaia / tools / mozdevice / util.js View on Github external
// Strip any whitespace at the end
      line = line.replace(/\s+$/g);

      if (!type) {
        type = util.getLogMessageType(line);
      }

      if (!type || !line.length) {
        return;
      }

      var message = {};
      var regex = PATTERNS[type];

      try {
        var match = XRegExp.exec(line, regex);
        var captureNames = regex.xregexp.captureNames;
        var fields = ['level', 'timestamp', 'pid', 'tid', 'tag', 'message'];

        fields.forEach(function(field) {
          if (captureNames.indexOf(field) >= 0) {
            message[field] = match[field];
          }
        });

        messages.push(message);
      } catch (e) {
        badLines++;
      }
    });
github connrs / node-find-hashtags / index.js View on Github external
FindHashtags.prototype._findNextMatch = function () {
  this._currentMatch = XRegExp.exec(this._content, hashtagExp, this._nextMatchPosition);
};
github azukiapp / azk / lib / azk / system / index.js View on Github external
return _.reduce(ports, (function(ports, port, name) {
      if (port == null)
        return ports;
      port = XRegExp.exec(port, regex_port);
      port.protocol = port.protocol || "tcp";
      var conf = {HostIp: config("agent:dns:ip")};
      if (port.public)
        conf.HostPort = port.public;
      ports[name] = {
        config: conf,
        name: port.private + "/" + port.protocol,
        private: port.private
      };
      return ports;
    }), {});
  },
github kilianc / node-apiserver-router / lib / router.js View on Github external
function getEndpointDescription(endpoint) {
  var xRegExp = XRegExp('(?[^/]+)/(?[^#]+)#(?.+)')
  var result = XRegExp.exec(endpoint, xRegExp)
  return {
    version: result.version,
    moduleName: result.moduleName,
    methodName: result.methodName
  }
}
github madskristensen / WebEssentials2013 / EditorExtensions / Resources / server / services / srv-icedcoffeescript.js View on Github external
var js = compiled.js;
            if (params.sourceMapURL !== undefined)
                js += "\n//# sourceMappingURL=" + path.basename(params.targetFileName) + ".map\n";

            writer.write(JSON.stringify({
                Success: true,
                SourceFileName: params.sourceFileName,
                TargetFileName: params.targetFileName,
                MapFileName: params.mapFileName,
                Remarks: "Successful!",
                Content: js,
                Map: JSON.stringify(map)
            }));
            writer.end();
        } catch (error) {
            var regex = xRegex.exec(error, xRegex(".*:.\\d*:.\\d*: error: (?(?.*)(\\n*.*)*)", 'gi'));
            writer.write(JSON.stringify({
                Success: false,
                SourceFileName: params.sourceFileName,
                TargetFileName: params.targetFileName,
                MapFileName: params.mapFileName,
                Remarks: "IcedCoffeeScript: An error has occured while processing your request.",
                Details: error.message,
                Errors: [{
                    Line: error.location.first_line,
                    Column: error.location.first_column,
                    Message: "IcedCoffeeScript: " + regex.message,
                    FileName: error.filename,
                    FullMessage: "IcedCoffeeScript: " + regex.fullMessage
                }]
            }));
            writer.end();
github madskristensen / WebEssentials2013 / EditorExtensions / Resources / server / services / srv-coffeescript.js View on Github external
var js = compiled.js;
            if (params.sourceMapURL !== undefined)
                js += "\n//# sourceMappingURL=" + path.basename(params.targetFileName) + ".map\n";

            writer.write(JSON.stringify({
                Success: true,
                SourceFileName: params.sourceFileName,
                TargetFileName: params.targetFileName,
                MapFileName: params.mapFileName,
                Remarks: "Successful!",
                Content: js,
                Map: JSON.stringify(map)
            }));
            writer.end();
        } catch (error) {
            var regex = xRegex.exec(error, xRegex(".*:.\\d*:.\\d*: error: (?(?.*)(\\n*.*)*)", 'gi'));
            writer.write(JSON.stringify({
                Success: false,
                SourceFileName: params.sourceFileName,
                TargetFileName: params.targetFileName,
                MapFileName: params.mapFileName,
                Remarks: "CoffeeScript: An error has occured while processing your request.",
                Details: regex.message,
                Errors: [{
                    Line: error.location.first_line,
                    Column: error.location.first_column,
                    Message: "CoffeeScript: " + regex.message,
                    FileName: error.filename,
                    FullMessage: "CoffeeScript: " + regex.fullMessage
                }]
            }));
            writer.end();
github kooohei / brackets-synapse / node / node_modules / ftp / lib / connection.js View on Github external
this._send('MDTM ' + path, function(err, text, code) {
    if (code === 502) {
      return self.list(path, function(err, list) {
        if (err)
          return cb(err);
        if (list.length === 1)
          cb(undefined, list[0].date);
        else
          cb(new Error('File not found'));
      }, true);
    } else if (err)
      return cb(err);
    var val = XRegExp.exec(text, REX_TIMEVAL), ret;
    if (!val)
      return cb(new Error('Invalid date/time format from server'));
    ret = new Date(val.year + '-' + val.month + '-' + val.date + 'T' + val.hour
                   + ':' + val.minute + ':' + val.second);
    cb(undefined, ret);
  });
};
github qiushi123 / xiaochengxu_demos / 014云开发实现小程序支付 / cloud / pay / node_modules / ftp / lib / connection.js View on Github external
this._send('MDTM ' + path, function (err, text, code) {
        if (code === 502) {
            return self.list(path, function (err, list) {
                if (err)
                    return cb(err);
                if (list.length === 1)
                    cb(undefined, list[0].date);
                else
                    cb(new Error('File not found'));
            }, true);
        } else if (err)
            return cb(err);
        var val = XRegExp.exec(text, REX_TIMEVAL), ret;
        if (!val)
            return cb(new Error('Invalid date/time format from server'));
        ret = new Date(val.year + '-' + val.month + '-' + val.date + 'T' + val.hour
            + ':' + val.minute + ':' + val.second);
        cb(undefined, ret);
    });
};