option setting

@exports safer
@function safer
@param {String} regex - check this string regex
@param {Boolean} [exception] - raise an exception if true
512281
function safer(regex, exception) {

  var e = exception === undefined ? true : Boolean(exception);
  var output;
  if (e) {
    output = function(err) {

      if (err) {
        throw new Error(err);
      }
    };
  } else {
    output = function(err) {

      return Boolean(!err);
    };
  }

  if (!regex || typeof regex !== 'string') { // string validation
    return output('argument must be a string');
  }

  try { // regex validation
    var _ = new RegExp(regex);
  } catch (err) {
    return output(err);
  }

  if (safe(regex) === false) {
    return output('regex is invalid or not safe');
  }
  return output();
}
697553
def regex(self, regex = None):
		

		# If regex was not set, this is a getter
		if regex is None:
			return self._regex

		# If the type is not a string
		if self._type != 'string':
			sys.stderr.write('can not set __regex__ for %s' % self._type)
			return

		# If it's not a valid string or regex
		if not isinstance(regex, (basestring, _REGEX_TYPE)):
			raise ValueError('__regex__')

		# Store the regex
		self._regex = regex
1186032
public PactDslJsonArray stringMatcher(String regex, String value) {
        if (!value.matches(regex)) {
            throw new InvalidMatcherException(EXAMPLE + value + "\" does not match regular expression \"" +
                regex + "\"");
        }
        body.put(value);
        matchers.addRule(rootPath + appendArrayIndex(0), regexp(regex));
        return this;
    }
959373
function(value, regExp) {
      if(regExp instanceof RegExp) {
        return value.match(regExp);
      }
      var
        regExpParts = regExp.match($.fn.form.settings.regExp.flags),
        flags
      ;
      // regular expression specified as /baz/gi (flags)
      if(regExpParts) {
        regExp = (regExpParts.length >= 2)
          ? regExpParts[1]
          : regExp
        ;
        flags = (regExpParts.length >= 3)
          ? regExpParts[2]
          : ''
        ;
      }
      return value.match( new RegExp(regExp, flags) );
    }
179327
function(props, regex) {
            if(!(regex instanceof RegExp)) {
                return props;
            }
            var key,
                filtered = {};

            for(key in props) {
                if(props.hasOwnProperty(key) && regex.test(key)) {
                    filtered[key] = props[key];
                }
            }
            return filtered;
        }
880827
def validate_regex(ctx, param, value):
    
    if not value:
        return None

    try:
        re.compile(value)
    except re.error:
        raise click.BadParameter('Invalid regex "{0}" provided'.format(value))

    return value
764174
function inlineRegex(regex) {
  return function match(source, state) {
    if (state.inline) {
      return regex.exec(source);
    } else {
      return null;
    }
  };
}
1352303
function isRegExp(value) {
    return value && objectTypes[typeof value] && toString.call(value) == regexpClass || false;
  }
1174176
function (format) {
            _validFormat(format);
    
            var m = _regexDecFormat.exec(format);
            if (m !== null)
                return (  (typeof m[3] === 'string') ? m[3].length : 0 )
                     + ( (m[4] === '%')              ? 2           : 0 );
            
            else {
                m = _regexFracFormat.exec(format);
                if (m !== null)
                    return _getPrecision(1 / parseInt(m[2], 10));
            }
            
            throw "IllegalArgumentException: format is not recognized (" + format + ")";
        }
1184997
public Regex then(Regex regex) {
      if (regex == null) {
         return this;
      }
      return re(this.pattern + regex.pattern);
   }
484669
function regexpToRegexp(regex, keys, options) {
  if (!Array.isArray(keys)) return regex.source;

  let groups = regex.source.match(/\((?!\?)/g);
  if (!groups) return regex.source;

  let i = 0;
  let group = () => ({
    name: i++,
    prefix: null,
    delimiter: null,
    optional: false,
    repeat: false,
    partial: false,
    pattern: null
  });

  groups.forEach(() => keys.push(group()));
  return regex.source;
}
791179
@Deprecated
  public static PactDslRootValue stringMatcher(String regex) {
    PactDslRootValue rootValue = new PactDslRootValue();
    rootValue.generators.addGenerator(Category.BODY, "", new RegexGenerator(regex));
    rootValue.setValue(new Generex(regex).random());
    rootValue.setMatcher(rootValue.regexp(regex));
    return rootValue;
  }
835956
function getRegex(regex, flags) {
  var result = typeOf(regex) === 'String'
    ? new RegExp(regex, flags || '')
    : regex

  if (typeOf(result) !== 'RegExp') {
    throw new Error(
      NAME + ': option "regex" must be a string or a RegExp object')
  }

  return result
}
66301
function handleArgs (_regex, _config) {
	/* Identify regex pattern. */
	let pattern;
	if (_regex) {
		if (typeof _regex === 'string') {
			pattern = _regex;
		} else {
			try {
				pattern = _regex.source;
			} catch (e) {
				log(`Invalid regex:`);
				log(_regex);
			}
		}
	} else {
		log(`Invalid regex: none provided`);
	}
	if (!pattern) {
		let errObj = { msg: 'Invalid args' };
		throw errObj;
	}

	/* Identify config. Accept a variety of flavors and fall back to defaults as needed. */
	let config = {};
	if (!_config) {
		config.server = defaultServerConfig;
		config.cache = defaultCacheConfig;
	} else {
		config.server = handleServerConfig(_config.server);
		config.cache = handleCacheConfig(_config.cache);
	}

	return [pattern, config];
}
172860
private static void checkPreconditions(final Pattern pattern, final String replacement) {
        if(pattern == null ) {
            throw new NullPointerException("regex should not be null");
        }
        
        if(replacement == null) {
            throw new NullPointerException("replacement should not be null");
        }
    }
799777
function toRegExp(val, def) {
    var exp = /^\/.+\/(g|i|m)?([m,i,u,y]{1,4})?/;
    var optsExp = /(g|i|m)?([m,i,u,y]{1,4})?$/;
    if (is_1.isRegExp(val))
        return val;
    if (!is_1.isValue(val) || !is_1.isString(val))
        return toDefault(null, def);
    function regExpFromStr() {
        var opts;
        if (exp.test(val)) {
            opts = optsExp.exec(val)[0];
            val = val.replace(/^\//, '').replace(optsExp, '').replace(/\/$/, '');
        }
        return new RegExp(val, opts);
    }
    return function_1.tryWrap(regExpFromStr)(def);
}
1333630
protected void validateRegex(String field, String regExpression, boolean isCaseSensitive, String errorKey, String errorMessage) {
        String value = controller.getPara(field);
        if (value == null) {
        	addError(errorKey, errorMessage);
        	return ;
        }
        Pattern pattern = isCaseSensitive ? Pattern.compile(regExpression) : Pattern.compile(regExpression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(value);
        if (!matcher.matches()) {
        	addError(errorKey, errorMessage);
        }
	}