Natural Language Processing · TEE · papers
Q1d · Five regex operators
2024-02-12 · re-exam · recovered AI paper
Previous examination · complete worked answers
Question. For word-pattern detection, explain: ^abc, abc$, [A-Z0-9], ed|ing|s, [abc]. [5 marks]
Answer
| Pattern | Exact meaning | Positive example | Important distinction |
|---|---|---|---|
| ^abc | abc at start of the input/line under chosen mode | abcdef | Not abc anywhere |
| abc$ | abc at end | xxabc | Not starts with abc |
| [A-Z0-9] | One uppercase ASCII letter or digit | Q or 7 | One character, not the whole string |
| ed|ing|s | One of the alternatives ed, ing or s | matched ed | Without anchors this is not necessarily a suffix |
| [abc] | One a, b or c | b | Not the three-character string abc |
Use full-string matching when the entire string must satisfy a pattern; a search may find only a substring.