Anchored Regex That Filters Well-Formed Requests

CS0-003 By islever Editorial Last updated

Short answer

D Use the anchored pattern ^https://10\.1\.2\.3/api\?id=[0-9]+$ so only fully well-formed GET requests are filtered and anomalies stay in the logs.

Question

A web application has a function to retrieve content from an internal URL to identify CSRF attacks in the logs. The security analyst is building a regular expression that will filter out the correctly formatted requests. The target URL is https://10.1.2.3/api, and the receiving API only accepts GET requests and uses a single integer argument named “id.” Which of the following regular expressions should the analyst use to achieve the objective?
  1. ^(?!https://10\.1\.2\.3/api\?id=[0-9]+)
  2. ^https://10\.1\.2\.3/api\?id=\d+
  3. (?:^https://10\.1\.2\.3/api\?id=[0-9]+)
  4. ^https://10\.1\.2\.3/api\?id=[0-9]+$ Correct Answer

Key Takeaways

The question tests full-string regex anchoring for log filtering; the trap is assuming a prefix match or a negative lookahead identifies a correctly formatted request.

This CS0-003 scenario tests building a regular expression that removes correctly formatted GET requests to https://10.1.2.3/api?id=<integer> from CSRF log review. The correct pattern is option D, anchored at both start and end for an exact full-string match.

Common mistake: Option A, a negative lookahead, is chosen by readers who parse 'filter out the correctly formatted requests' as 'show only bad requests' — but it has no end anchor, so URLs with extra parameters or trailing payload still begin with a valid prefix and get discarded as correct.

Expert Analysis

What the pattern has to prove

The analyst's filter exists to remove requests that are provably well-formed from the CSRF review queue, so the regex must positively identify exactly one shape: https://10.1.2.3/api plus a single integer id. That makes D (^https://10\.1\.2\.3/api\?id=[0-9]+$) correct, because ^ and $ together demand that the entire log field — not a fragment of it — is the expected URL.

Why the unanchored variants are dangerous

Option B is the classic near-miss: \d+ will happily match the leading digits of id=12<script> or id=7&redirect=evil, so a request carrying an injected extra parameter or payload is classified as correct and filtered away. Option C drops both anchors, so the pattern can match anywhere inside a longer or re-redirected URL. Both yield false negatives — malicious traffic silently leaves the queue while analysts triage noise.

The negative-lookahead trap

One line of reasoning argues that ^(?!...) is right because the question says "filter out the correctly formatted requests" and that construct "will only display wrong format." It fails technically: the lookahead tests only the prefix and has no end condition, so https://10.1.2.3/api?id=5&next=https://evil begins with a valid prefix, the lookahead refuses to match, and that request is discarded as correct — exactly the CSRF-style anomaly the filter exists to expose.

What would flip the answer

If the API accepted multiple or optional parameters, or the goal were to highlight only malformed entries rather than suppress good ones, the required pattern would change. Under the stated constraints — one integer argument, exact URL — anchoring mistakes translate directly into false negatives, which is why full-string matching is the doctrine tested here.

Official Reference

https://www.comptia.org/certifications/cybersecurity-analyst

This link opens the official vendor documentation in a new tab.

Exam Strategy

Read the required format as a checklist — scheme, host, path, parameter name, data type — then demand that the pattern covers all of it from ^ to $ before considering alternatives. When two options differ only by anchors, choose the fully anchored one for filtering tasks, because unanchored patterns create false negatives in log triage. Treat any negative-lookahead option as a distractor unless the question explicitly asks to surface only nonconforming entries, and verify it still enforces the end of the string.

Frequently Asked Questions

Why does a log-filtering regex need both ^ and $?

Anchors force a full-string match, so only a request that is entirely the expected URL with an integer id is treated as well-formed. Without $, a pattern such as id=\d+ also matches malicious prefixes like id=12<script>, creating false negatives.

What happens if the analyst uses option B instead of D?

Option B lacks the end anchor, so any request whose id value starts with digits — including id=7&redirect=evil — is filtered out as correct. Suspicious traffic disappears from the review queue while analysts spend time on clean entries.

When would a negative lookahead like option A be appropriate?

Only when the goal is explicitly to surface entries that do not conform to a known good pattern, and even then the pattern must enforce the full expected structure. Here it misclassifies requests with extra parameters as correct, so it fails the objective.

More CS0-003 FAQ →

Community Votes

D
80%
A
20%

80% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.

Discussion 6 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 6

  1. hashed_pony 👍 18 Answered D
    Who's going to memorize regex for an exam? You have to be kidding... Anyway, just memorized it start with an ^ and ends with a $ sign. -_-
  2. Popeyes_Chicken 👍 5 Answered D
    D. ^https://10\.1\.2\.3/api\?id=[0-9]+$ Matches the URL exactly from start (^) to end ($), making sure no extra characters exist before or after the URL. It meets all the stated requirements.
  3. Robuste7 👍 5 Answered D
    I’m taking the exam on next Sunday, I’m putting this in my memory ^…$,
  4. 4ee1800 👍 2 Answered D
    ^...$ = Perfectly matches the entire string.
  5. agfencer 👍 1
    Did anyone read the question? It's asking to filter OUT the correct ones, and only display wrong format ^(?! = does not match the regex to follow the answer is A
Show 1 more comment
  1. idts0987 👍 1
    how did you do?

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

← Back to CS0-003 Study Guide