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.
Warm-up questions
Short questions with short answers, each answered in full.
-
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
-
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
-
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.
-
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
-
- Which single change to the Python call refuses the line feed and keeps the pattern text?
- Why did the Go job skip rows when its own pattern looks the same?
- How do you find and repair the rows already stored?
- What test keeps the Python and Go rules from drifting apart?
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.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
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
-
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
-
- Why does the HTML field refuse values that the schema accepts?
- What does ^SKU-[0-9]{4}|LEGACY$ accept in a schema, and why is it still wrong?
- Which Python call checks the same text as the whole-value rule?
- Where must the check run again, and why?
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
-
Mid to senior
A recipe site highlights whole-word hits with a Python pattern built as \b, the term, \b. Searching cafe highlights the first four letters of café in text pasted from one app, but nothing in typed text, and searching café finds nothing in the pasted text. What differs between the two texts, and how do you fix the search?
- What it tests
- Knowing that an accent can be stored as a combining mark of its own, how each flavour's word characters treat marks, and normalising both text and term before matching.
- First step
- Print the code points of the pasted word. If its é is e followed by U+0301 COMBINING ACUTE ACCENT, the decomposed form, the two texts differ: Python's \w leaves the mark out, so a boundary falls between e and the accent, and the precomposed é of a typed term does not occur in the pasted text at all.
- Follow-ups
-
- Why does the same search behave differently in PHP with the u modifier?
- Does normalising the text also settle searches in Hindi?
- How do you put each highlight back in the right place after normalising?
- Which test cases keep this from coming back?
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
-
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
-
- Why does that pattern count two adjacent names as one?
- How do you keep a term such as C++ from being read as pattern syntax?
- What should be highlighted, when every match includes its neighbours?
- When would you split the line into words instead of searching for the term?
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