Skip to content

Instantly share code, notes, and snippets.

@viniceosm
Last active June 28, 2018 03:33
Show Gist options
  • Save viniceosm/937c469b0dfa0e3562c0a9fa96053855 to your computer and use it in GitHub Desktop.
Save viniceosm/937c469b0dfa0e3562c0a9fa96053855 to your computer and use it in GitHub Desktop.
regex include and exclude

two pattern

let validate = (str) => {
	let required = /(\$.*\$)/i; // Regex include - tem que te-lo
	let blocked = /(\$\()/i; // Regex exclude - não tem que te-lo
	return required.test(str) && !blocked.test(str);
}

one pattern

let validate = (str) => {
	let one = /(?=.*(\$.*\$))(?!.*(\$\())(.+)/i;
	return one.test(str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment