Regex

RegExr: Learn, Build, & Test RegEx
Regular expression tester with syntax highlighting, PHP / PCRE & JS Support, contextual help, cheat sheet, reference, and searchable community patterns.
https://regexr.com/

https://www.youtube.com/watch?v=rhzKDrUiJVk&ab_channel=WebDevSimplified

Basics and flags

/query goes here/flags

flags
g - global: searches all text, not just first find
i - case insensitive
m - multiline
u - unicode
y - sticky

Basic querys

/cat/ - finds cat

/e+/ - match as many in a row as you can

/a+e?/ - find list of a and optionally get e

/./ - matches anything except new line

/\./ - selects .

/^I/ - selects I from the very start of the line

/$I/ - selects I from the very end of the line

\ - Presets

// NOTE CAPITAL MEAN REVERSE
/\w/ - selects all alphaneumeric and _
/\s/ - selects white space
/\./ - selects .

{ } - Length Selector

\w{4,5}\ - select a w 4 to 5 char long, till white space

[ ] - Range

/[cr]at/ - match anything starting in 'c' or 'r' and ending in 'at'
for example 'cat' or 'rat' 

--- selects range ---

[A-Z]
[a-z]
[0-9]

( ) - Group

/(t|T)/ - select t or T

Look Behind/Ahead

--- look behind ---
/(?<=word)./ - selects the char after word
/(?<!word)./ - selects anything but the char after word

--- look ahead ---
/.(?=word)/ - selects the char that is before word
/.(?!word)/ - selects anything but the char before word

Groups

--- groups are anything inside ()
/.(?<groupName>[A-Z])/