12 November 2021

| and ?

Regex Cheat Sheet

Attention VSCode Users! You can search programs using regexes! We vim users have had this all along.


[a-zQ5&#]    list/range character class
[^a-zQ5&#]   snotty character class: anything but chars shown
m                this non-magic character is just.... m.
.                any character except \n
\s               whitespace
\S               anthing not whitespace
\d               digit
\D               non-digit
\w               any alpha character or _
\W               anything but an  alpha character or _

Magic charcters in list character classes:

[                start list character class
]                end list character class
-                indicaes a range
^                when first, makes a list character class snotty

Assertions :

^                start of line
$                end of line
\b               word boundary
\B               not word boundary

Multiplicity Operators

*                zero or more
+                one or more
{n}              exactly n of
{m, n}           at leasat m nbut not more than n of
{m,}             m or more
?                once or not at all

Operators

juxtaposition    "and then immediately"
|                or
(... )           override order of operations


Magic Toggler:

\

Example \? is a question mark, not a multiplicty operator
d is the nonmagic letter d, \d is a digit.

Java
java.util.regex package.  Note that in Java a \\ is needed for a \.

Python:
re                        the regular expression package
                          tip: use raw strings for regexes.

match an integer:    ^[+\-]?\d+$

Or example:  match these three

Amy Sheck is bonkers.
John Morrison is loony!
John Morrison is crazy



^(Amy Sheck|John Morrison) is (bonkers|loony|crazy)[!.]?$

greed. What is greed?
You might want to learn about greed
Waht is a grou?
What is capturing?


The PFM makes me want to cry.
The PFM makes me want to die!
Physics makes me want to crawl under a rock
Physics makes me want to die

^(The PFM|Physics) makes me want to (cry|die|crawl under a rock)[.!]?$

ababababababababa   (could end in a or b)

^(ab)+a?$



















Block F
Pratham Patel, Archita Khaire, Isha Madeshwar
Eric Liu, Eric Chen, Ivan Zheng
Hong Liu, Alden Warner, Meseker Workukebede
Ben Warren, Niccolo Luftig, Jacob
Melody Lee, Shreednidhi Prakki, Krasinski, Shaffer
Jack Hao
Block B
Max VanFleet, Jake Deng Tres Frisard
Lucia Wang, Kendal Win
Al Pagar, Sophia Dai
Ari Etijn, Riley Wild
Joseph Swoers, Chris Agrella, John Miller
Sathvik Chatta, Shohei Tsuboyama, Ani Doki
Destiny Okonkwo