Library › Coding AI › College students
Explain a regex piece by piece in 5 numbered lines
Practice: Asking for a format you can use. About 5 minutes.
About this exercise
You found the regex below in your course-planner project and want to understand it. Ask for exactly 5 numbered lines, one per piece in order (^[A-Z]{2,4}, the space, \d{3,4}, [A-Z]?, $), each like '1. ^[A-Z]{2,4} - meaning' with the meaning under 12 words. Then two lines, 'Matches: <code>' and 'Doesn't match: <code>', each using a code from your catalog list. No code blocks, under 110 words.
Common mistakes when you ask AI for this
- Getting a table or essay. The AI explains regex in general, with headings or a table. Try: Say: "Exactly 5 numbered lines, one per piece, each under 12 words."
- Splitting it its own way. The AI breaks the pattern into 8 or 9 tiny tokens, so your 5 questions get lost. Try: List the pieces: "^[A-Z]{2,4}, the space, \\d{3,4}, [A-Z]?, $."
- Fuzzy meanings. Without a cap, meanings ramble; with one, the AI sometimes says {2,4} means 'exactly 2 or 4'. Try: Show it: "1. ^[A-Z]{2,4} - 2 to 4 capital letters at the start".
- No check against your data. The AI invents examples instead of testing your catalog list. Try: Add: "End with Matches: and Doesn't match: lines using codes from my list."
What a strong prompt includes
- Sets the number of lines
- Lists the pieces
- Caps each meaning
- Asks for examples from your list
- Rules out code blocks
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)