Hone

Lessons · Regex · literal characters

Characters match themselves

A plain pattern like error finds those exact characters anywhere in the text.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

The first regex anyone writes is a word to search for in a log.

How to think about it

Is plain text enough? Start with the literal text. Add special characters only when plain text is not enough.

Worked example

pattern: warn
Four plain characters.
text: a warning was logged
Matches 'warn' inside 'warning'.
text: all clear
No match.

Your turn

Find the word 'fail' in a line.

The trap

Assuming a literal matches only whole words. It matches inside other words too; that is what \b is for.

Practise literal characters on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.