Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Regular Expressions Module 3

Anchors and boundaries interview questions

Interview questions on anchors and boundaries: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

7 questions: 3 warm-ups and 4 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher to mid

    What do ^ and $ match, and what changes when multiline mode is on?

    Answered in the lesson Anchors: start, end and multiline mode

  2. Fresher to mid

    How do \z and \Z differ, and which one should end a validator?

    Answered in the lesson Anchors: start, end and multiline mode

  3. Fresher to mid

    What does \b match, and why does \bcat\b find cat in cat-flap but not in cat_food?

    Answered in the lesson Word boundaries and whole-word search

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Mid to senior

    A Python worker validates voucher codes with re.match(r"^[A-Z0-9]{8}$", code) before inserting them into a table with a unique key. Support finds SAVE2026 stored twice, once with an invisible extra character, and a Go job that reads the table skips some rows. What happened, and how do you fix the check and the rows?

    What it tests
    Knowing that Python's $ also holds before a final line feed while Go's means the very end, and repairing both the check and the data it already let in.
    First step
    Print the repr of one duplicate and look for a trailing line feed. If it is there, the pattern did what Python's dollar allows, and the unique key saw two different strings. Then decide whether surrounding line breaks are refused or cleaned before the check.
    Follow-ups

    From the lesson Anchors: start, end and multiline mode

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Mid to senior

    A product form uses pattern="SKU-[0-9]{4}|LEGACY" and behaves as intended. The same text in a JSON Schema "pattern" keyword accepts "xSKU-12345" and "OLD LEGACY". Explain both behaviours, then write one pattern text that is correct in the form, the schema and a Python service.

    What it tests
    Knowing that the HTML attribute is wrapped in anchors and a group while JSON Schema patterns are not anchored, and that a bar needs a group before anchors bind to it.
    First step
    Write down what the HTML Standard compiles from the attribute and what the schema keyword compiles, then run both on one rejected and one accepted value. The difference is the anchors, and the bar decides where they bind.
    Follow-ups

    From the lesson Anchors: start, end and multiline mode

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Mid to senior

    A log tool lets users filter lines with a pattern in RE2 syntax and offers no way to run code. Users want a whole-word filter for product names in English, Hindi and Tamil, plus a report of how often each name occurs. How do you write the pattern, and where does it fall short?

    What it tests
    Knowing that RE2's \b is ASCII and that RE2 has no lookaround, matching the neighbours instead of testing them, and seeing which jobs that serves and which it breaks.
    First step
    State the two limits first: RE2's \b is an ASCII word boundary, and RE2 refuses lookbehind and lookahead. So the neighbours have to be matched, not only tested: the start of the line or one character that cannot continue a word before the term, and the end of the line or one such character after it, with the term in a group.
    Follow-ups

    From the lesson Word boundaries and whole-word search

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes

All Regular Expressions interview questions · The Regular Expressions track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.