Intro to Regex
“Regular expressions“, sometimes referred to as “rational expressions” or “regex”, are can be a powerful tool when used properly. Generally, regex is a sequence of characters that defines a search pattern across a string. This can be handy in many cases, such as validating a credit card, or social security number, making sure an email address is in the proper format, or even for tools such as profanity filters.
Below, are some great helper sheets to refer to when creating or reading regex expressions.
g, i, & m are placed at the end of your regex to modify your searches.
The bracket and carrot notation system, coupled with the metacharacters below allow us to create extremely precise and complex expressions.
exec() & test() are commonly used to evaluate regex. Note that exec() returns the first match, while test() returns a boolean.
For more examples, check out one of my other blog posts on implementing a simple Social Security Number regex in javascript.