How to use the xregexp.XRegExp 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 walling / unorm / examples / basic-usage / basic-usage-in-node.js View on Github external
// String optimized for compatibility, ie. CO₂ becomes CO2.
var scientific = "CO\u2082 and E=mc\u00B2";
console.log("- Example 3 -");
console.log(scientific);
console.log(scientific.normalize("NFKC"));

// NOTE: Rest of the example requires XRegExp: npm install xregexp

// Remove combining characters / marks from Swedish name, ie. ö becomes o.
// This is useful for indexing and searching internationalized text.
try {
	var xregexp = require("xregexp").XRegExp;
	var name = "\u00C5ngstr\u00F6m";
	console.log("- Example 4 -");
	console.log(name.normalize("NFKD"));
	console.log(name.normalize("NFKD").replace(xregexp("\\p{M}", "g"), ""));
} catch (ex) {}
github UWNetworksLab / uProxy-p2p / src / generic_ui / scripts / translator.ts View on Github external
function isRightToLeft(lang :string): boolean {
  return xregexp.XRegExp('[\\p{Arabic}\\p{Hebrew}]').test(lang);
}
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 markbirbeck / pos-chunker / lib / recursiveMatch.js View on Github external
function recursiveMatch(str, rregexp) {
  var regexp = new XRegExp(expand(rregexp), 'gm');

  var results = [];
  return XRegExp.forEach(str, regexp, function(match) {
    if (match.lookbehind) {

      /**
       * Find our lookbehind value:
       */

      var ix = match.indexOf(match.lookbehind);

      /**
       * If the lookbehind value is in the middle of the list of groups then
       * grab all remaining elements to comprise our return value, otherwise
       * return the entire matched pattern:
       */
github azukiapp / azk / lib / azk / docker / pull.js View on Github external
"use strict";
var __moduleName = "src/docker/pull";
var $__0 = require('azk'),
    Q = $__0.Q,
    _ = $__0._,
    defer = $__0.defer;
var XRegExp = require('xregexp').XRegExp;
var $__0 = require('azk/utils/errors'),
    ProvisionNotFound = $__0.ProvisionNotFound,
    ProvisionPullError = $__0.ProvisionPullError;
var msg_regex = {
  pulling_another: new XRegExp('Repository.*another'),
  pulling_repository: new XRegExp('Pulling repository (?.*)'),
  pulling_layers: new XRegExp('Pulling dependent layers'),
  pulling_metadata: new XRegExp('Pulling metadata'),
  pulling_fs_layer: new XRegExp('Pulling fs layer'),
  pulling_image: new XRegExp('Pulling image \((?.*)\) from (?.*), endpoint: (?.*)'),
  download: new XRegExp('Downloading'),
  download_complete: new XRegExp('Download complete')
};
function parse_status(msg) {
  var result = {};
  _.find(msg_regex, (function(regex, type) {
    var match = XRegExp.exec(msg, regex);
    if (match) {
      result['type'] = type;
      _.each(regex.xregexp.captureNames, function(key) {
        if (match[key]) {
          result[key] = match[key];
github azukiapp / azk / lib / azk / docker / pull.js View on Github external
"use strict";
var __moduleName = "src/docker/pull";
var $__0 = require('azk'),
    Q = $__0.Q,
    _ = $__0._,
    defer = $__0.defer;
var XRegExp = require('xregexp').XRegExp;
var $__0 = require('azk/utils/errors'),
    ProvisionNotFound = $__0.ProvisionNotFound,
    ProvisionPullError = $__0.ProvisionPullError;
var msg_regex = {
  pulling_another: new XRegExp('Repository.*another'),
  pulling_repository: new XRegExp('Pulling repository (?.*)'),
  pulling_layers: new XRegExp('Pulling dependent layers'),
  pulling_metadata: new XRegExp('Pulling metadata'),
  pulling_fs_layer: new XRegExp('Pulling fs layer'),
  pulling_image: new XRegExp('Pulling image \((?.*)\) from (?.*), endpoint: (?.*)'),
  download: new XRegExp('Downloading'),
  download_complete: new XRegExp('Download complete')
};
function parse_status(msg) {
  var result = {};
  _.find(msg_regex, (function(regex, type) {
    var match = XRegExp.exec(msg, regex);
    if (match) {
      result['type'] = type;
      _.each(regex.xregexp.captureNames, function(key) {
        if (match[key]) {
github cgiffard / Downsize / index.js View on Github external
var downsize = function (text, inputOptions, offset) {
        var stack = [],
            pointer = 0,
            tagName = "",
            parseState = 0,
            trackedState = {unitCount: 0, countState: false},
            tagBuffer = "",
            truncatedText = "";

        var COUNT_CHARACTERS = -1,
            COUNT_WORDS = -2;

        var options = inputOptions && typeof inputOptions === "object" ? inputOptions : {},
            wordChars = options.wordChars instanceof RegExp ?
                options.wordChars : new XRegexp("[\\p{L}0-9\\-\\']", "i");

        options.countingType =
            !isNaN(Number(options.words)) ? COUNT_WORDS : COUNT_CHARACTERS;

        if (options.round) {
            options.contextualTags = defaultContextualTags;
        }

        options.keepContext     = !!options.contextualTags;
        options.contextualTags  = 
            options.keepContext && Array.isArray(options.contextualTags) ?
                options.contextualTags : [];

        options.limit =
            (options.countingType === COUNT_WORDS) ?
                Number(options.words) : Number(options.characters);
github madskristensen / WebEssentials2013 / EditorExtensions / Resources / server / services / srv-scss.js View on Github external
writer.write(JSON.stringify({
                    Success: true,
                    SourceFileName: params.sourceFileName,
                    TargetFileName: params.targetFileName,
                    MapFileName: params.mapFileName,
                    Remarks: "Successful!",
                    Content: css,
                    Map: JSON.stringify(map)
                }));
            }

            writer.end();
        }
        else {
            var error = fs.readFileSync(params.targetFileName);
            var regex = xRegex.exec(error, xRegex("Error: (?(?.*))\r\n +?on line (?
github markbirbeck / pos-chunker / lib / recursiveMatch.js View on Github external
function recursiveReplace(str, rregexp, newsubstr) {
  var regexp = new XRegExp(expand(rregexp), 'gm');
  return XRegExp.replace(str, regexp, function(match) {
    var subststr = newsubstr;

    /**
     * To emulate lookbehind a named group has been used. If it contains
     * a value then we need to juggle the results a little. For example,
     * if the parameters are:
     *
     *  replace('abc def', /(?<=abc )def/, '{$1}');
     *
     * then the callback will receive:
     *
     *  match = 'abc def'
     *  match.lookbehind = 'abc '
     *
     * We can then use these values to emulate lookbehind, by:
github madskristensen / WebEssentials2013 / EditorExtensions / Resources / server / services / srv-sweetjs.js View on Github external
var js = compiled.code;
            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(".+:.*?\\n*.*?Line.+\\d+: (?.*(\\n*.*)*)", 'gi'));
            var message = regex ? regex.fullMessage : "Unknown error.";

            writer.write(JSON.stringify({
                Success: false,
                SourceFileName: params.sourceFileName,
                TargetFileName: params.targetFileName,
                MapFileName: params.mapFileName,
                Remarks: "SweetJS: An error has occured while processing your request.",
                Details: error.description,
                Errors: [{
                    Line: error.lineNumber,
                    Column: error.column,
                    Message: "SweetJS: " + (error.description || message),
                    FileName: params.sourceFileName,
                    FullMessage: "SweetJS: " + message
                }]