Docsity

Spyder Forensics Applied RegEx using PowerShell Exam, Exams of Technology

Toggle sidebar
bg1
Spyder Forensics Applied RegEx using PowerShell Exam
**Question 1. Which RegEx meta‑character matches any single character except a newline?**
A) `*`
B) `+`
C) `.`
D) `?`
Answer: C
Explanation: The dot (`.`) is the wildcard that matches any single character except line‑terminators.
**Question 2. In PowerShell, which operator is used to test if a string contains a pattern?**
A) `-contains`
B) `-match`
C) `-like`
D) `-replace`
Answer: B
Explanation: The `-match` operator evaluates a regular expression against a string and returns a
Boolean.
**Question 3. Which character class represents any digit?**
A) `\w`
B) `\d`
C) `\s`
D) `\b`
Answer: B
Explanation: `\d` is the shorthand for the digit character class `[0-9]`.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b

Partial preview of the text

Download Spyder Forensics Applied RegEx using PowerShell Exam and more Exams Technology in PDF only on Docsity!

Question 1. Which RegEx meta‑character matches any single character except a newline? A) * B) + C) . D) ? Answer: C Explanation: The dot (.) is the wildcard that matches any single character except line‑terminators. Question 2. In PowerShell, which operator is used to test if a string contains a pattern? A) -contains B) -match C) -like D) -replace Answer: B Explanation: The -match operator evaluates a regular expression against a string and returns a Boolean. Question 3. Which character class represents any digit? A) \w B) \d C) \s D) \b Answer: B Explanation: \d is the shorthand for the digit character class [0-9].

Question 4. What does the quantifier {3,5} mean? A) Exactly three occurrences B) Between three and five occurrences, inclusive C) At least three occurrences D) Zero to five occurrences Answer: B Explanation: {min,max} specifies a minimum and maximum number of repetitions. Question 5. Which of the following regex patterns will match a valid IPv4 address segment (0‑255)? A) \d{1,3} B) (25[0-5]|2[0-4]\d|[01]?\d\d?) C) [0-9]{1,3} D) \b\d{1,3}\b Answer: B Explanation: The pattern accounts for the range limits of each octet (0‑255) using alternation. Question 6. In PowerShell, which automatic variable stores the results of a successful -match operation? A) $match B) $Matches C) $Result D) $found Answer: B Explanation: $Matches is a hashtable containing named and numbered capture groups.

Question 10. How would you replace every occurrence of "admin" with "root" in a variable $text using PowerShell? A) $text - replace "admin","root" B) $text.Replace("admin","root") C) Set-Content $text - Value "admin" "root" D) Update-String $text admin root Answer: A Explanation: The -replace operator takes a regex pattern and a replacement string. Question 11. Which look‑ahead assertion checks that a string is followed by ".exe" without including it in the match? A) (?=\.exe) B) (?<=\.exe) C) (?!\.exe) D) (?<!.exe) Answer: A Explanation: Positive look‑ahead (?=…) asserts the presence of the following pattern without consuming it. Question 12. Which shorthand class matches any whitespace character? A) \w B) \d C) \s D) \b Answer: C Explanation: \s matches spaces, tabs, line breaks, etc.

Question 13. To match a literal dot in a regex, which escape sequence is required? A) . B) \. C) \\. D) [:.] Answer: B Explanation: The dot is a meta‑character; escaping with \. treats it as a literal period. Question 14. Which quantifier makes the preceding token lazy (non‑greedy)? A) * B) +? C) {2,} D) ? Answer: B Explanation: Adding ? after a quantifier (*?, +?, {m,n}?) makes it lazy, matching as few characters as possible. Question 15. In a PowerShell script, how can you split a log line on one or more spaces using a regex? A) $line - split "\s+" B) $line.Split(" ") C) $line - split "[ ]" D) $line - split "\w" Answer: A Explanation: -split "\s+" uses a regex to split on any sequence of whitespace characters.

Question 19. Which PowerShell cmdlet can be used to validate that an input parameter matches a regex pattern? A) ValidatePattern attribute B) Test-Regex C) Assert-Pattern D) Check-Regex Answer: A Explanation: The [ValidatePattern()] attribute validates parameter values against a regex at runtime. Question 20. How would you write a regex that matches a Social Security Number (SSN) while preventing obvious invalid numbers like "000- 00 - 0000"? A) \d{3}-\d{2}-\d{4} B) (?!000|666)[0-8]\d{2}-(?!00)\d{2}-(?!0000)\d{4} C) \b\d{3}-\d{2}-\d{4}\b D) (?<!\d)\d{3}-\d{2}-\d{4}(?!\d) Answer: B Explanation: The pattern uses negative look‑ahead to exclude disallowed groups (e.g., 000, 666, etc.). Question 21. Which regex pattern would correctly extract the domain from an email address like "[email protected]"? A) .+@(.+) B) (?<=@)[^@]+ C) (?<=@)[\w\.]+ D) Both B and C Answer: D

Explanation: Both use a look‑behind to assert the @ and then capture characters up to the next delimiter. Question 22. In PowerShell, what does the -notmatch operator do? A) Returns the inverse Boolean of -match B) Throws an exception if the pattern is not found C) Replaces the pattern with an empty string D) Splits the string on the pattern Answer: A Explanation: -notmatch evaluates to $true when the regex does not match the input. Question 23. Which quantifier matches zero or one occurrence of the preceding token? A) * B) + C) ? D) {0,1} Answer: C Explanation: ? is the optional quantifier, matching either none or a single occurrence. Question 24. To avoid catastrophic backtracking when matching long strings of repetitive characters, which technique is recommended? A) Use greedy quantifiers exclusively B) Prefer atomic groups or possessive quantifiers C) Remove all anchors D) Increase the regex engine timeout Answer: B

Answer: D Explanation: https?:// matches http:// or https://; both A and C are valid with slight differences. Question 28. What does the regex pattern (?<=\s)ERROR(?=\s) match? A) The word "ERROR" only when surrounded by whitespace B) Any line containing "ERROR" C) The word "ERROR" at the start of a line D) The word "ERROR" at the end of a line Answer: A Explanation: Positive look‑behind and look‑ahead assert whitespace before and after "ERROR" without including it. Question 29. Which PowerShell method safely escapes a string that contains regex meta‑characters before using it in a pattern? A) [regex]::Escape() B) StringEscape() C) Escape-Regex D) ConvertTo-EscapedString Answer: A Explanation: [regex]::Escape() returns a string with all regex meta‑characters escaped. Question 30. Which regex token matches any word character (letters, digits, underscore)? A) \w B) \d C) \s D) \b

Answer: A Explanation: \w is the shorthand for [A-Za-z0-9_]. Question 31. To capture the process ID (PID) from a line like "PID: 1234" using a named group, which pattern is correct? A) PID:\s+(?<PID>\d+) B) PID:\s+(?<Id>\d+) C) PID:\s+(\d+) D) PID:\s+(?<PID>\w+) Answer: A Explanation: The named group PID captures one or more digits after the label. Question 32. Which quantifier would you use to require at least three repetitions but no more than six? A) {3,6} B) {3,} C) {,6} D) +{3,6} Answer: A Explanation: {min,max} specifies a lower and upper bound; {3,6} means 3‑6 repetitions. Question 33. In a forensic script, you need to extract credit‑card numbers that pass the Luhn check. Which regex component is essential before applying the algorithm? A) \d{13,19} B) \b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14})\b C) \d{4}-\d{4}-\d{4}-\d{4}

C) Atomic group (?>…) D) Named group (?<name>…) Answer: B Explanation: Negative look‑ahead (?!pattern) ensures the following characters do not match the pattern. Question 37. To split a CSV line on commas except when the comma is inside quotes, which regex would you use with -split? A) ",(?=(?:[^"]*"[^"]*")*$)" B) (?<=,)(?=(?:[^"]*"[^"]*")*$) C) ,(?=(?:[^"]*"[^"]*")*$) D) (?<!")\,(?!") Answer: C Explanation: The pattern matches commas that have an even number of quotes ahead, meaning they are outside quoted fields. Question 38. Which of the following patterns will match a Windows file path like C:\Program Files\App\app.exe? A) [A-Z]:\\(?:[^\\\/:*?"<>|]+\\)*[^\\\/:*?"<>|]+ B) ([A-Za-z]:\\)+ C) C:\\.* D) \w:\\.* Answer: A Explanation: This pattern respects invalid filename characters and allows nested folders. Question 39. In PowerShell, which operator would you use to replace only the first occurrence of a pattern?

A) -replace with a count parameter B) -replace with a regex that limits to one match (^) C) -replace (it replaces all by default) – you must limit with a regex like (?s).*?pattern D) -replace cannot limit to first; use .Replace() method with count Answer: D Explanation: The string method .Replace(old,new, count) can limit replacements; -replace always replaces all matches. Question 40. Which regex anchor matches the end of a string, regardless of multiline mode? A) $ B) \Z C) \z D) Both B and C, but not A in multiline Answer: C Explanation: \z matches the absolute end of the input; $ can match before a final newline when multiline is on. Question 41. What does the pattern (?<!\d)\d{4}(?!\d) capture? A) Any four‑digit number that is not part of a larger number B) Any four‑digit number at the start of a line C) Any four‑digit number preceded by a digit Question 41. What does the pattern (?<!\d)\d{4}(?!\d) capture? A) Any four‑digit number that is not part of a larger number B) Any four‑digit number at the start of a line C) Any four‑digit number preceded by a digit D) Any four‑digit number followed by a letter

B) $escaped = $userInput - replace '[.*?]' C) $escaped = $userInput.Trim() D) $escaped = $userInput - join '' Answer: A Explanation: [regex]::Escape() adds backslashes before every regex meta‑character, making the string safe for literal matching. Question 45. Which quantifier matches exactly three repetitions of the preceding token? A) {3} B) +{3} C) *3 D) ?{3} Answer: A Explanation: {n} specifies an exact number of repetitions; {3} means “exactly three”. Question 46. To extract the Event ID from a Windows Event Log line like EventID: 4624, which regex pattern should be used? A) EventID:\s*(\d+) B) (?<=EventID:\s*)\d+ C) EventID:\s*\b(\d{4})\b D) All of the above Answer: D Explanation: All three patterns correctly locate and capture the numeric ID; B uses a look‑behind, A and C use capturing groups. Question 47. Which PowerShell cmdlet can be used to search the contents of multiple log files for a pattern and also display the three lines before and after each match?

A) Select-String - Context 3,3 B) Get-Content - Tail 3 C) Find-String - Surround 3 D) Search-File - ContextLines 3 Answer: A Explanation: Select-String’s -Context <pre>,<post> parameter shows surrounding lines. Question 48. Which of the following regex patterns will correctly match a GUID (e.g., 3F2504E0- 4F89-41D3-9A0C-0305E82C3301) in a case‑insensitive manner? A) [0-9A-Fa-f]{8}-(?:[0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12} B) \b[0-9A-F]{8}(-[0-9A-F]{4}){3}-[0-9A-F]{12}\b C) (?i)[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12} D) All of the above Answer: D Explanation: Each pattern accounts for the hyphenated hexadecimal groups; C explicitly sets case‑insensitivity with (?i). Question 49. Which regex feature allows you to match a pattern only if it is not preceded by a specific substring? A) Positive look‑behind (?<=…) B) Negative look‑behind (?<!…) C) Positive look‑ahead (?=…) D) Non‑capturing group (?:…) Answer: B Explanation: Negative look‑behind asserts that the preceding characters do not match the given subpattern.

Question 53. To match a Windows service name that may contain spaces but never starts with a digit, which pattern is appropriate? A) ^[^\d]\w+(?:\s\w+)*$ B) ^[^\d]\S*(?:\s\S+)*$ C) ^(?!\d)[\w\s]+$ D) All of the above Answer: D Explanation: Each pattern uses a negative look‑ahead or character class to prevent a leading digit and allows spaces thereafter. Question 54. Which of the following regex statements correctly extracts the version number from a string like Version: 3.7.2.1 using a named capture group called Ver? A) Version:\s*(?<Ver>\d+(\.\d+)+) B) Version:\s*(?<Ver>\d+(\.\d+){3}) C) Version:\s*(?<Ver>\d+(\.\d+){0,3}) D) All of the above (they differ only in allowed sub‑versions) Answer: D Explanation: All patterns capture the version; B limits to exactly four components, C allows up to four, A allows any number of dot‑separated components. Question 55. Which regex construct is used to ignore the case of the pattern without embedding an inline option? A) (?i) at the start of the pattern B) (?-i) at the start of the pattern C) (?s) at the start of the pattern D) (?m) at the start of the pattern

Answer: A Explanation: (?i) toggles case‑insensitive matching for the remainder of the pattern. Question 56. In PowerShell, which operator would you use to test whether a string does not contain any digits? A) -notmatch '\d' B) -notcontains '\d' C) -replace '\d','' D) -match '\D' Answer: A Explanation: -notmatch returns $true when the regex fails; \d looks for digits, so the expression checks for the absence of digits. Question 57. Which regex pattern will correctly match a range of ports from 1024 to 49151 (inclusive) expressed as decimal numbers? A) \b(?:[1-9]\d{3}|[1-3]\d{4}|4[0-8]\d{3}|49[0-1]\d{2}|492[0-9]{2}|493[0-1]\d|4932[0-9]|4933[0-1])\b B) \b(?:[1-9]\d{3}|[1-3]\d{4}|4[0-8]\d{3}|49[0-1]\d{2}|492[0-9]{2}|493[0-1]\d|4932[0-9]|4933[0-1])\b C) \b(?:[1-9]\d{3}|[1-3]\d{4}|4[0-8]\d{3}|49[0-1]\d{2}|492[0-9]{2}|493[0-1]\d|4932[0-9]|4933[0-1])\b D) None of the above – regex alone cannot reliably enforce numeric ranges without excessive complexity. Answer: D Explanation: While technically possible, encoding the entire numeric range is impractical and error‑prone; a script should parse the number and compare numerically. Question 58. Which of the following patterns extracts a hexadecimal MD5 hash (32 hex characters) from a log line? A) \b[a-fA-F0-9]{32}\b