{"id":"code-col-explain-regex-five-pieces","audience":"college","category":"coding","track":"coding","technique":"format","title":"Explain a regex piece by piece in 5 numbered lines","free":false,"task":"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.","materialLabel":"The regex and your catalog list (attached to your prompt automatically)","material":"// planner/validate.js  (my course-planner side project)\nconst COURSE_CODE = /^[A-Z]{2,4} \\d{3,4}[A-Z]?$/;\n\nexport function isCourseCode(text) {\n  return COURSE_CODE.test(text);\n}\n\nCourse codes copied from the Fall catalog PDF:\n  CS 1010\n  MATH 221L\n  BIOL 1500\n  ENGL 101W\n  HIST 3020\n  CS 10\n  PSYCH 1100\n  cs 2110\n  CHEM 1210 L\n\nThings I'm not sure about:\n- what the {2,4} part does exactly\n- whether the ? makes the letter optional or the whole thing\n- why \"PSYCH 1100\" fails when it's a real course (my friend said\n  regex is \"broken\" but I think it's on purpose?)\n\nI copied the regex from a Stack Overflow answer, so I didn't\nwrite it myself.","rules":[{"type":"numberedItems","count":5},{"type":"codeBlocks","count":0},{"type":"maxProseWords","max":110}],"mistakes":[{"title":"Getting a table or essay","why":"The AI explains regex in general, with headings or a table.","fix":"Say: \"Exactly 5 numbered lines, one per piece, each under 12 words.\"","checks":["numberedItems","maxProseWords"]},{"title":"Splitting it its own way","why":"The AI breaks the pattern into 8 or 9 tiny tokens, so your 5 questions get lost.","fix":"List the pieces: \"^[A-Z]{2,4}, the space, \\\\d{3,4}, [A-Z]?, $.\"","checks":["r0"]},{"title":"Fuzzy meanings","why":"Without a cap, meanings ramble; with one, the AI sometimes says {2,4} means 'exactly 2 or 4'.","fix":"Show it: \"1. ^[A-Z]{2,4} - 2 to 4 capital letters at the start\".","checks":["r1"]},{"title":"No check against your data","why":"The AI invents examples instead of testing your catalog list.","fix":"Add: \"End with Matches: and Doesn't match: lines using codes from my list.\"","checks":["r2","codeBlocks"]}],"promptHints":[{"label":"Sets the number of lines","patterns":["\\b(5|five)\\b.{0,20}(line|piece|part)","one per piece"]},{"label":"Lists the pieces","patterns":["\\{2,4\\}","\\[A-Z\\]\\?","pieces"]},{"label":"Caps each meaning","patterns":["\\d+\\s*words"]},{"label":"Asks for examples from your list","patterns":["matches:","doesn'?t match","my list","catalog"]},{"label":"Rules out code blocks","patterns":["no code"]}],"hint":"To really learn a regex, see each piece next to what it means, then test it on your own data. Tell the AI the pieces, the line shape and how to end.","rubricLabels":["The 5 numbered lines cover exactly these pieces in order: ^[A-Z]{2,4}, the single space, \\d{3,4}, [A-Z]?, and $","The meanings are right: ^[A-Z]{2,4} is 2 to 4 capital letters at the start, \\d{3,4} is 3 or 4 digits, [A-Z]? is one optional capital letter, and $ is the end of the text","After line 5 there are exactly two lines, 'Matches: ' with a listed code that really matches (e.g. MATH 221L) and 'Doesn't match: ' with a listed code that really doesn't (e.g. PSYCH 1100, CS 10 or cs 2110)"]}