Regular Expressions Flashcards
Show how to search if ‘where’ is at the beginning of the sentence
^where
Select every possible character
.
In terms of the below list, use a character set to find all of them.
Find all words except those using a character set
bar ber bir bor bur
b[eioua]r
b[^aeiou]r
Find all letters e through o
[e-o]
Show how you would search the below and get all the words using e in our search. We are fine with e showing up one or more times, or just never
br ber beer
be*r
Search for everything except for br below. So we want to search for if e occurs one or more times, but not never
be+r
Search saying the u in color is optional (zero or one, not zero, one or more.)
color colour
colou?r
Search for words that start with ‘be’ and end with 4.
be should only occur only two times and that’s it.
Now show if we want the e character to show up AT LEAST 3 times in a row.
Now show words that e can show up 1 - 3 times
be{2}r
be{3,}r
be{1,3}r
Show an expression that would find 4 numbers in a row
[0-9]{4}
Create two groups, one that contains ‘ha’ and the other that contains ‘haa’
(ha)-\1,(haa)-\2
What is a pip character used for?
Allows you to specify that and express can be in different expressions.
use a pipe character to select all from the below
cat rat dog
(c|r)at|dog
What is the escape character?
\
use the escape character to find
* and .
(*|.)
Search for only the numbers at the beginning of the statements
- this
- that
- other
^[0-9]
Find only the expressions that end with html
https://domain.com/what-is-html.html
https://otherdomain.com/html-elements
https://website.com/html5-features.html
html$
Use the word Character to find letters numbers and underscores
\w
Use the Except Word Character to find characters other than letters, numbers, and underscores.
\W
use the Number Character to only find number characters
\d
use the Except Number Character to only find everything but number characters
\D
Use the Space Character to find space characters
\s
Use the Except Space Character to find everything except space characters
\S
What do we use if we want to search for a phrase we’re writing to come before or after another phrase?
a Lookaround
Using a Lookahead, find only the three character.
Next, look for only numbers that don’t have pm after them with the Negative Lookahead
Date: 4 Aug 3PM
\d+(?=PM)
\d+(?!PM)
Using the Positive Lookbehind, find only the numbers preceeded by a $ sign
Next find numbers that aren’t preceeded by the $ sign
Product Code: 1064 Price: $5
(?<=$)\d+
(?<!$)\d+