How to use regex-parser - 2 common examples

To help you get started, we’ve selected a few regex-parser 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 gajus / surgeon / src / subroutines / testSubroutine.js View on Github external
const testSubroutine = (subject: string, [userRule]: $ReadOnlyArray) => {
  const rule: RegExp = parseRegex(userRule);

  if (typeof subject !== 'string') {
    throw new SurgeonError('Input is not a string.');
  }

  if (!rule.test(subject)) {
    return new InvalidValueSentinel('Input does not match "' + rule.toString() + '" regular expression.');
  }

  return subject;
};
github gajus / surgeon / src / subroutines / matchSubroutine.js View on Github external
const matchSubroutine = (subject: string, [userRule, sprintfFormat]: $ReadOnlyArray) => {
  const rule: RegExp = parseRegex(userRule);

  if (typeof subject !== 'string') {
    throw new SurgeonError('Input is not a string.');
  }

  const matches = subject.match(rule);

  if (!matches) {
    log.debug({
      input: subject,
    }, 'input');

    return new InvalidValueSentinel('Input does not match "' + rule.toString() + '" regular expression.');
  }

  if (matches.length === 1) {

regex-parser

A module that parses a string as regular expression and returns the parsed value.

MIT
Latest version published 7 months ago

Package Health Score

73 / 100
Full package analysis

Popular regex-parser functions