Jacob Johns

aspiring developer

Regular Expressions

Often shortened to regex or regexp, are patterns that help match, search, & replace text

Test Method

Testing is important! Returns a boolean


Different Possibilities

Use the alternation or OR operator |


Ignore Case

i flag ignores case


Extract Matches

.match() method to extract


More than the First Match

g flag returns more than the first in a pattern


Match anything - Wildcard Period

Wildcard is . (period) not * (star)


Single Character with Multiple Possibilities

Character Classes - these define a group of characters to match by placing them in square brackets


Letters of the Alphabet

Inside a character set a range of characters can be defined using a hyphen character -


Numbers & Letters of the Alphabet

Hyphen - also works on numbers. Number & letter ranges can be combined in a single character set as well


Single Characters Not Specified

Negated character sets are sets of characters no one wants :(


Characters that Occur One or More Times

+ to match character(s) that appears one or more times in a row


Characters that Occur Zero or More Times

Star *


Lazy Matching

Finds the smallest possible part of the string that satisfies the regex pattern


Criminal Hunt Challenge

Dun dun dun!


Beginning String Patterns

^ outside of a character set ([]) searchs for patterns at the beginning of strings


Ending String Patterns

$ searches the end of strings for patterns


All Letters & Numbers

Shorthand character class \w is the closest to match the alphabet


Everything BUT Letters & Numbers

\W matches that opposite to \w


All Numbers

\d for just digits


All Non-Numbers

\D is all non-numbers


Restrict Usernames Challenge

Usernames be everywhere


Whitespace

\s to find whitespace


Non-Whitespace

\S.... DUH


Upper & Lower Number of Matches

Quantity specifiers {} specify the lower and upper number of patterns


Only the Lower Number of Matches

Leave out the second number, keep the comma


Exact Number of Matches

Just one number no comma


All or None

Possible existence of an element can be checked with ?


Positive & Negative Lookahead

Lookaheads are patterns that tell JS to lookahead in a string for patterns further along


Mixed Group of Characters

To check for groups of characters use ()


Reuse Patterns Using Capture Groups

Search for repeat substrings using capture groups


Capture Gropus to Search & Replace

.replace(exampleRegex, "replace with me")


Remove Whitespace from Start & End

Typical processing


RegEx Lesson Complete Image

*NOTE*
Gave each section its own... well section. Regex can be complicated so I wanted to break out the practice to clearly show the work