0
0
PowerShellscripting

Regex quantifiers and anchors in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the regex quantifier * mean?
The * quantifier means "match zero or more occurrences" of the preceding character or group. For example, a* matches '', 'a', 'aa', 'aaa', and so on.
Click to reveal answer
beginner
What is the difference between + and ? quantifiers in regex?
+ means "one or more occurrences" while ? means "zero or one occurrence" of the preceding element. For example, a+ matches 'a', 'aa', 'aaa', but not ''. a? matches '' or 'a'.
Click to reveal answer
beginner
What does the anchor ^ do in a regex pattern?
The ^ anchor matches the start of a string. For example, ^Hello matches 'Hello world' but not 'Say Hello'.
Click to reveal answer
beginner
What does the anchor $ do in a regex pattern?
The $ anchor matches the end of a string. For example, world$ matches 'Hello world' but not 'world peace'.
Click to reveal answer
beginner
In PowerShell, how would you check if a string starts with 'Test' using regex anchors?
You can use the -match operator with the pattern ^Test. For example: 'Test string' -match '^Test' returns True because the string starts with 'Test'.
Click to reveal answer
What does the regex quantifier ? mean?
AOne or more occurrences
BZero or more occurrences
CZero or one occurrence
DExactly one occurrence
Which regex anchor matches the end of a string?
A^
B$
C\b
D\A
In PowerShell, which operator is used to test if a string matches a regex pattern?
A-match
B-eq
C-contains
D-like
What does the regex quantifier + require at minimum?
AOptional occurrence
BZero occurrences
CTwo occurrences
DOne occurrence
What does the regex pattern ^abc$ match?
AStrings exactly equal to 'abc'
BStrings starting with 'abc'
CStrings ending with 'abc'
DAny string containing 'abc'
Explain how regex quantifiers *, +, ? differ and give a simple example for each.
Think about how many times the character can appear.
You got /4 concepts.
    Describe how anchors ^ and $ help in matching patterns in strings.
    Anchors fix the position in the string where the match must occur.
    You got /3 concepts.