Regex 101 Flashcards
What is Regex?
Short for regular expression, a regex is a string of text that allows you to create patterns that help match, locate, and manage text.
What is the left and the right side of this called?:
action=time532
field and value
Both they create a field-value pair
What does Regex do?
a) Filtering - it eliminates unwanted data from your searches
b) Matching - advanced pattern matching to find the results you need
c) Field extraction - labels bits of data that can be used for further calculation and analysis
What does Control Characters (anchors) do?
They tell regex where to start and stop looking
What control characters do you know? What do they do?
^ - start of a line
$ - end of a line
\b - whole words only
\B - bordered by word characters
What are character Classes?
Character classes distinguish kinds of characters such as, for example, distinguishing between letters and digits
What are the character classes that you know? What do they do?
\s - white space
\S - not a white space
\d - digit
\D - non-digit
\w -word-character (includes letters, numbers and underscore)
\W - non-word character
How to define symbolic character?
use \
How to anchor start of a line?
How to anchor end of a line?
$
How to define the border by whole words only?
\b
How to define the border by word characters?
\B
What’s the character class for white space?
\s
What’s the character class for not a white space?
\S
What’s the character class for digit?
\d
What’s the character class for non-digit?
\D
What’s the character class for word-character?
\w
What’s the character class for non-word character?
\W
What are operators?
They define how many of character types to grab
What operators you know? What do they do?
* - zero or more
+ - one or more
? - Zero or more
What is the Operator for zero or more?
*
What is the operator for one or more?
+
What is the operator for zero or one?
?
What is a Greedy regex?
Greedy regex means that your regex statement is using a operator that keeps gobbling up matches until it is interrupted
What is a Lazy regex?
Lazy regex means your regex will only match the first occurence of the pattern you are looking for before it stops
What are special characters?
Those are the characters that symbolize something else.
For Example *+?$/[]{}()
What is the symbol for “OR” condition?
|
What is the special character for matching any character?
.
What is a protection character?
It identifies given letter as a special character, or special character as a literal match
What is the protection character?
\ (backslash, escape)
What are the inclusion characters?
[]
What are the exclusion characters?
[^]
What is repetition?(regex)
Tells regex how many times you want to pick up on an pattern
How would you use pattern repetitions in regex?
How would you set up logical groupings?
With ()
How would you use logical groupings?
What are named capture groups?
They extract the value and assign named field to it
How would you use Named Capture Groups?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
They tell regex where to start and stop looking
What does Control Characters (anchors) do?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
^ - start of a line
$ - end of a line
\b - whole words only
\B - bordered by word characters
What control characters do you know? What do they do?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
Character classes distinguish kinds of characters such as, for example, distinguishing between letters and digits
What are character Classes?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
\s - white space
\S - not a white space
\d - digit
\D - non-digit
\w -word-character (includes letters, numbers and underscore)
\W - non-word character
What are the character classes that you know? What do they do?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
use \
How to define symbolic character?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
How to anchor start of a line?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
$
How to anchor end of a line?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
\b
How to define the border by whole words only?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
\B
How to define the border by word characters?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
\s
What’s the character class for white space?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
\S
What’s the character class for not a white space?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
\d
What’s the character class for digit?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
\D
What’s the character class for non-digit?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
\w
What’s the character class for word-character?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
\W
What’s the character class for non-word character?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
They define how many of character types to grab
What are operators?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
* - zero or more
+ - one or more
? - Zero or one
What operators you know? What do they do?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
*
What is the Operator for zero or more?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
+
What is the operator for one or more?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
?
What is the operator for zero or one?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
|
What is the symbol for “OR” condition?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
.
What is the special character for matching any character?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
[]
What are the inclusion characters?
This is the “reversed” card. It first displays you the answer and you have to guess the question part of it.
[^]
What are the exclusion characters?
\w+[A-Z]
(\d+-){2}\d+ \d+-\d+-\d+
\w+,\s[A-Z]+
\b[A-Z]\w+
\w+(?=@)
What is negative lookahead and how it works?
(?!)
Find experssion A where expression B does not follow:
A(?!B)
What is positive lookahead and how it works?
(?=)
Find experssion A where expression B follows:
A(?=B)
What is positive lookbehind and how does it work?
(?<=)
Find expression A where expression B precedes:
(?<=B)A
What is negative lookbehind and how does it work?