How to use the 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 zencrepes / zencrepes / imports / ui / data / utils / ingestIssue.js View on Github external
issueObj['refreshed'] = true;
  issueObj['points'] = null;
  issueObj['boardState'] = null;

  //The data version module is used to identify when the data model has changed and it is necessary to clear the cache.
  // For now only doing this for issues
  issueObj['data_version'] = Meteor.settings.public.data_version;

  if (issueObj.labels !== undefined) {
    //Get points from labels
    // Regex to test: SP:[.\d]
    //let pointsExp = RegExp('SP:[.\\d]');
    let pointsExp = XRegExp('SP:[.\\d]');
    //let pointsLabelExp = RegExp('loe:(?.+)');
    //let boardExp = RegExp('(?AB):(?[.\\d]):(?.+)');
    let boardExp = XRegExp('(?AB):(?[.\\d]):(?.+)');
    for (var currentLabel of issueObj.labels.edges) {
      if (pointsExp.test(currentLabel.node.name)) {
        let points = parseInt(currentLabel.node.name.replace('SP:', ''));
        issueObj['points'] = points;
      } else if (pointsExp.test(currentLabel.node.description)) {
        let points = parseInt(currentLabel.node.description.replace('SP:', ''));
        issueObj['points'] = points;
      } else if (
        Meteor.settings.public.labels.effort !== undefined &&
        Meteor.settings.public.labels.effort[currentLabel.node.name] !==
          undefined &&
        Number.isInteger(
          Meteor.settings.public.labels.effort[currentLabel.node.name]
        )
      ) {
        // Interesting edge case, if the label is actually named "constructor"
github elastic / kibana / x-pack / plugins / reporting / export_types / printable_pdf / server / lib / pdf / index.js View on Github external
function getFont(text) {
  // Once unicode regex scripts are fully supported we should be able to get rid of the dependency
  // on xRegExp library.  See https://github.com/tc39/proposal-regexp-unicode-property-escapes
  // for more information. We are matching Han characters which is one of the supported unicode scripts
  // (you can see the full list of supported scripts here: http://www.unicode.org/standard/supported.html).
  // This will match Chinese, Japanese, Korean and some other Asian languages.
  const isCKJ = xRegExp('\\p{Han}').test(text, 'g');
  if(isCKJ) {
    return 'noto-cjk';
  } else {
    return 'Roboto';
  }
}
github sogehige / sogeBot / src / bot / systems / moderation.ts View on Github external
async blacklist (opts: ParserOptions) {
    const enabled = await this.getPermissionBasedSettingsValue('cListsEnabled');
    const timeout = await this.getPermissionBasedSettingsValue('cListsTimeout');
    const permId = await permissions.getUserHighestPermission(opts.sender.userId);

    if (permId === null || !enabled[permId]) {
      return true;
    }

    let isOK = true;
    for (const value of this.cListsBlacklist.map(o => o.trim().replace(/\*/g, '[\\pL0-9]*').replace(/\+/g, '[\\pL0-9]+'))) {
      if (value.length > 0) {
        const regexp = XRegExp(` [^\\s\\pL0-9\\w]?${value}[^\\s\\pL0-9\\w]? `, 'gi');
        // we need to change 'text' to ' text ' for regexp to correctly work
        if (XRegExp.exec(` ${opts.message} `, regexp)) {
          isOK = false;
          this.timeoutUser(opts.sender, opts.message,
            translate('moderation.user-is-warned-about-blacklist'),
            translate('moderation.user-have-timeout-for-blacklist'),
            timeout[permId], 'blacklist');
          break;
        }
      }
    }
    return isOK;
  }
github passbolt / passbolt_browser_extension / src / all / data / js / quickaccess / popup / components / HomePage / canSuggestUrl.js View on Github external
}

  port = suggestedUrlObject.port;
  if (!enforceProtocol) {
    protocol = suggestedUrlObject.protocol;
    hostname = suggestedUrlObject.hostname;
  } else {
    suggestedUrlObject.protocol = "https:";
    hostname = suggestedUrlObject.hostname;
  }

  return {protocol, hostname, port};
};

// Hostname allowed characters regex
const regexHostnameAllowedChars = XRegExp('^[\\p{L}\\p{N}.-]*$');

/**
 * Check a hostname is parent of another on.
 * Note, the function does not ensure the validity of the hostnames.
 *
 * By instance for a given hostname: accounts.passbolt.com
 * The following hostnames should match:
 * - accounts.passbolt.com
 * - passbolt.com
 *
 * The following hostnames should not match:
 * - passbolt.com.attacker.com
 * - attacker-passbolt.com
 *
 * @param {string} parent the hostname to check if it is parent.
 * @param {string} hostname The hostname to check if it is a child.
github gchq / CyberChef / src / core / operations / Regex.js View on Github external
s = args[4],
            u = args[5],
            a = args[6],
            displayTotal = args[7],
            outputFormat = args[8];
        let modifiers = "g";

        if (i) modifiers += "i";
        if (m) modifiers += "m";
        if (s) modifiers += "s";
        if (u) modifiers += "u";
        if (a) modifiers += "A";

        if (userRegex && userRegex !== "^" && userRegex !== "$") {
            try {
                const regex = new XRegExp(userRegex, modifiers);

                switch (outputFormat) {
                    case "Highlight matches":
                        return Regex._regexHighlight(input, regex, displayTotal);
                    case "List matches":
                        return Utils.escapeHtml(Regex._regexList(input, regex, displayTotal, true, false));
                    case "List capture groups":
                        return Utils.escapeHtml(Regex._regexList(input, regex, displayTotal, false, true));
                    case "List matches with capture groups":
                        return Utils.escapeHtml(Regex._regexList(input, regex, displayTotal, true, true));
                    default:
                        return "Error: Invalid output format";
                }
            } catch (err) {
                return "Invalid regex. Details: " + err.message;
            }
github zencrepes / zencrepes / imports / ui / components / Pullrequest / PullrequestWide.js View on Github external
render() {
    const { classes, pullrequest } = this.props;
    //const pointsExp = RegExp('SP:[.\\d]');
    //const boardExp = RegExp('(?AB):(?[.\\d]):(?.+)');
    const pointsExp = XRegExp('SP:[.\\d]');
    const boardExp = XRegExp('(?AB):(?[.\\d]):(?.+)');
    return (
      
        
          
            
              {pullrequest.state === 'OPEN' ? (
                Open
              ) : (
github ik9999 / searx-term / src / View / MainContent / SearchResults / ListItem.js View on Github external
let contentWithTags = '';
  let contentHeight = 0;
  if (searchResultData.content) {
    contentStr = searchResultData.content;
    let wordWrapRegex = '.{1,' + maxWidth + '}(\s|$)' + '|.{' + maxWidth + '}|.+$';
    let contentStrSplit = contentStr.match(RegExp(wordWrapRegex, 'g'));
    contentHeight = contentStrSplit.length;
    contentWithTags = contentStrSplit.join('\n');
  }

  let prettyUrlTxt = '';
  if (searchResultData.prettyUrl) {
    prettyUrlTxt = searchResultData.prettyUrl;
  }

  XRegExp.forEach(query, XRegExp('[\\p{L}|\']+', 'g'), match => {
    titleWithTags = titleWithTags.replace(new RegExp('(' + match[0] + ')', 'gi'), '{bold}$1{/bold}');
    contentWithTags = contentWithTags.replace(new RegExp('(' + match[0] + ')', 'gi'), '{bold}$1{/bold}');
  });

  let title = blessed.text({
    top: 0,
    left: 0,
    height: 1,
    width: '100%',
    align: 'left',
    content: listIdx + '. {underline}' + titleWithTags + '{/underline}',
    tags: true
  });
  let content = blessed.text({
    top: 1,
    left: 0,
github zencrepes / zencrepes / imports / ui / components / Pullrequest / PullrequestWide.js View on Github external
render() {
    const { classes, pullrequest } = this.props;
    //const pointsExp = RegExp('SP:[.\\d]');
    //const boardExp = RegExp('(?AB):(?[.\\d]):(?.+)');
    const pointsExp = XRegExp('SP:[.\\d]');
    const boardExp = XRegExp('(?AB):(?[.\\d]):(?.+)');
    return (
      
        
          
            
              {pullrequest.state === 'OPEN' ? (
                Open
              ) : (
                
                  {pullrequest.state === 'CLOSED' ? (
github gchq / CyberChef / src / core / operations / legacy / Extract.js View on Github external
break;
            case "16-bit bigendian":
                strings = `(\x00${strings})`;
                break;
            case "Single byte":
            default:
                break;
        }

        strings = `${strings}{${minLen},}`;

        if (matchType.includes("Null-terminated")) {
            strings += "\x00";
        }

        const regex = new XRegExp(strings, "ig");

        return Extract._search(input, regex, null, displayTotal);
    },
github thm-projects / arsnova-flashcards / imports / api / markdeep.js View on Github external
content = content.replace(new XRegExp(config.plantUML.regexp.pre + config.plantUML.regexp.content + config.plantUML.regexp.post, "gs"), function (match) {
			match = match.replace(new XRegExp(config.plantUML.regexp.pre, "gs"), config.plantUML.output.pre);
			match = match.replace(new XRegExp(config.plantUML.regexp.post, "gs"), config.plantUML.output.post);
			let result = asciidoctor.convert(match);
			let doc = new DOMParser().parseFromString(result, "text/html");
			if (doc.getElementsByTagName("img").length) {
				if (Route.isPresentation() || Route.isEditMode()) {
					doc.getElementsByTagName("img")[0].style.width = Session.get('currentZoomValue') + "%";
				} else {
					doc.getElementsByTagName("img")[0].style.width = "100%";
				}
				if (doc.getElementsByTagName("h2").length) {
					let item = doc.getElementsByTagName("h2")[0];
					item.parentNode.removeChild(item);
				}
				return doc.documentElement.innerHTML;
			} else {
				return result;